Ejemplo n.º 1
0
func testSanityCheck() (success bool) {
	defer func() {
		if r := recover(); r != nil {
			println("Error in sanity-check test")
			if s, ok := r.(string); ok {
				println(s)
			}
			success = false
		}
	}()
	user := "******"
	password := "******"
	url, _ := fosp.ParseURL(user + "@" + host + "/")
	child, _ := fosp.ParseURL(user + "@" + host + "/foo")
	obj1, _ := fosp.UnmarshalObject(`{"data": "foo"}`)
	obj2, _ := fosp.UnmarshalObject(`{"data": "bar"}`)
	objNoWrite, _ := fosp.UnmarshalObject(`{ "acl": { "owner": ["not-data-write"], "users": { "` + user + "@" + host + `" : [ "not-data-write" ] } } }`)
	attachment := []byte("Hello World!")

	client := &fosp.Client{}
	err := client.OpenConnection(host)
	if err != nil {
		println("Failed to open connection")
		success = false
		return
	}
	expectE(client.Connect())
	expectE(client.Register(user, password))
	expectE(client.Authenticate(user, password))
	expectE(client.Select(url))
	expectE(client.List(url))
	expectE(client.Create(child, obj1))
	expectE(client.List(url))
	expectE(client.Update(child, obj2))
	expectE(client.Delete(child))
	expectFailed(client.Delete(child))
	expectE(client.Create(child, obj1))
	expectE(client.Update(child, objNoWrite))
	expectFailed(client.Update(child, obj2))
	expectE(client.Write(child, attachment))
	expect(E{Body: string(attachment)})(client.Read(child))
	success = true
	return
}
Ejemplo n.º 2
0
Archivo: acl.go Proyecto: geoah/go-fosp
func testAcl() (success bool) {
	defer func() {
		if r := recover(); r != nil {
			println("Error in access control test")
			if s, ok := r.(string); ok {
				println(s)
			}
			success = false
		}
	}()

	userOne := "alice"
	passwordOne := "password"
	clientOne := &fosp.Client{}
	err := clientOne.OpenConnection(host)
	if err != nil {
		panic("Failed to open connection for client one.")
	}
	expectE(clientOne.Connect())
	expectE(clientOne.Register(userOne, passwordOne))
	expectE(clientOne.Authenticate(userOne, passwordOne))

	userTwo := "bob"
	passwordTwo := "password"
	clientTwo := &fosp.Client{}
	err = clientTwo.OpenConnection(host)
	if err != nil {
		panic("Falied to open connection for client two.")
	}
	expectE(clientTwo.Connect())
	expectE(clientTwo.Register(userTwo, passwordTwo))
	expectE(clientTwo.Authenticate(userTwo, passwordTwo))

	rootOne, err := fosp.ParseURL(userOne + "@" + host)
	if err != nil {
		panic("Error when parsing root URL of user one")
	}

	expect(E{Failed: true})(clientTwo.Select(rootOne))
	return true
}