Commit 3cbaad14 authored by ale's avatar ale

Test /api/user/get with varying group memberships

parent 2f146082
Pipeline #1421 passed with stages
in 1 minute and 39 seconds
...@@ -59,9 +59,8 @@ type testClient struct { ...@@ -59,9 +59,8 @@ type testClient struct {
signer sso.Signer signer sso.Signer
} }
func (c *testClient) ssoTicket(username string) string { func (c *testClient) ssoTicket(username string, groups ...string) string {
var groups []string if len(groups) == 0 && username == testAdminUser {
if username == testAdminUser {
groups = append(groups, testAdminGroup) groups = append(groups, testAdminGroup)
} }
signed, err := c.signer.Sign(sso.NewTicket(username, testSSOService, testSSODomain, "", groups, 1*time.Hour)) signed, err := c.signer.Sign(sso.NewTicket(username, testSSOService, testSSODomain, "", groups, 1*time.Hour))
...@@ -164,19 +163,25 @@ func TestIntegration_GetUser_Auth(t *testing.T) { ...@@ -164,19 +163,25 @@ func TestIntegration_GetUser_Auth(t *testing.T) {
testdata := []struct { testdata := []struct {
authUser string authUser string
authGroup string
expectedOk bool expectedOk bool
}{ }{
{"uno@investici.org", true}, {"uno@investici.org", "", true},
{"due@investici.org", false}, {"uno@investici.org", "users", true},
{testAdminUser, true}, {"due@investici.org", "users", false},
{testAdminUser, testAdminGroup, true},
} }
for _, td := range testdata { for _, td := range testdata {
var user accountserver.User var user accountserver.User
var groups []string
if td.authGroup != "" {
groups = append(groups, td.authGroup)
}
err := c.request("/api/user/get", &accountserver.GetUserRequest{ err := c.request("/api/user/get", &accountserver.GetUserRequest{
RequestBase: accountserver.RequestBase{ RequestBase: accountserver.RequestBase{
Username: "uno@investici.org", Username: "uno@investici.org",
SSO: c.ssoTicket(td.authUser), SSO: c.ssoTicket(td.authUser, groups...),
}, },
}, &user) }, &user)
if td.expectedOk && err != nil { if td.expectedOk && err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment