search_test.go 1.63 KB
Newer Older
ale's avatar
ale committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
package integrationtest

import (
	"testing"

	as "git.autistici.org/ai3/accountserver"
)

func TestIntegration_SearchIsAdminPrivileged(t *testing.T) {
	stop, _, c := startService(t)
	defer stop()

	var resp as.SearchUserResponse
	if err := c.request("/api/user/search", &as.SearchUserRequest{
		AdminRequestBase: as.AdminRequestBase{
			RequestBase: as.RequestBase{
				SSO: c.ssoTicket("uno@investici.org"),
			},
		},
		Pattern: "uno@investici.org",
	}, &resp); err == nil {
		t.Fatal("no error for user-privileged SearchUser!")
	}
}

func TestIntegration_SearchUser(t *testing.T) {
	stop, _, c := startService(t)
	defer stop()

	var resp as.SearchUserResponse
	if err := c.request("/api/user/search", &as.SearchUserRequest{
		AdminRequestBase: as.AdminRequestBase{
			RequestBase: as.RequestBase{
				SSO: c.ssoTicket(testAdminUser, testAdminGroup),
			},
		},
		Pattern: "uno@investici.org",
	}, &resp); err != nil {
		t.Fatal(err)
	}
	if len(resp.Usernames) != 1 {
		t.Fatalf("expected 1 result, got %d", len(resp.Usernames))
	}
	if resp.Usernames[0] != "uno@investici.org" {
		t.Fatalf("got bad username '%s', expected uno@investici.org", resp.Usernames[0])
	}
}

func TestIntegration_SearchResource(t *testing.T) {
	stop, _, c := startService(t)
	defer stop()

	var resp as.SearchResourceResponse
	if err := c.request("/api/resource/search", &as.SearchResourceRequest{
		AdminRequestBase: as.AdminRequestBase{
			RequestBase: as.RequestBase{
				SSO: c.ssoTicket(testAdminUser, testAdminGroup),
			},
		},
		Pattern: "due*",
	}, &resp); err != nil {
		t.Fatal(err)
	}
	if len(resp.Results) != 4 {
		t.Fatalf("expected 4 results, got %d", len(resp.Results))
	}
}