Commit 4c21ce02 authored by ale's avatar ale
Browse files

Simplify integration test with common getUser() function

parent 66a3e2d6
Pipeline #24841 passed with stages
in 3 minutes and 23 seconds
......@@ -242,15 +242,7 @@ func TestIntegration_AppSpecificPassword_Create(t *testing.T) {
t.Fatalf("CreateApplicationSpecificPassword failed: %v", err)
}
var user as.User
err = c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket(testAdminUser, testAdminGroup),
},
Username: username,
},
}, &user)
user, err := c.getUser(username)
if err != nil {
t.Fatalf("GetUser error: %v", err)
}
......@@ -285,15 +277,7 @@ func TestIntegration_AppSpecificPassword_Delete(t *testing.T) {
t.Fatalf("DeleteApplicationSpecificPassword failed: %v", err)
}
var user as.User
err = c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket(testAdminUser, testAdminGroup),
},
Username: username,
},
}, &user)
user, err := c.getUser(username)
if err != nil {
t.Fatalf("GetUser error: %v", err)
}
......@@ -332,15 +316,7 @@ func TestIntegration_EnableOTP_WithoutSecret(t *testing.T) {
t.Errorf("TOTP secret unset in response")
}
var user as.User
err = c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket(testAdminUser, testAdminGroup),
},
Username: username,
},
}, &user)
user, err := c.getUser(username)
if err != nil {
t.Fatalf("GetUser error: %v", err)
}
......@@ -374,15 +350,7 @@ func TestIntegration_EnableOTP_WithSecret(t *testing.T) {
t.Errorf("wrong TOTP secret returned in response")
}
var user as.User
err = c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket(testAdminUser, testAdminGroup),
},
Username: username,
},
}, &user)
user, err := c.getUser(username)
if err != nil {
t.Fatalf("GetUser error: %v", err)
}
......@@ -409,15 +377,7 @@ func TestIntegration_DisableOTP(t *testing.T) {
t.Fatalf("DisableOTP failed: %v", err)
}
var user as.User
err = c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket(testAdminUser, testAdminGroup),
},
Username: username,
},
}, &user)
user, err := c.getUser(username)
if err != nil {
t.Fatalf("GetUser error: %v", err)
}
......
......@@ -151,6 +151,19 @@ func (c *testClient) request(uri string, req, out interface{}) error {
return json.Unmarshal(data, out)
}
func (c *testClient) getUser(username string) (*as.User, error) {
var user as.User
err := c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket(testAdminUser, testAdminGroup),
},
Username: username,
},
}, &user)
return &user, err
}
func startServiceWithConfigAndCache(t *testing.T, svcConfig as.Config, enableCache bool) (func(), as.Backend, *testClient) {
// Tell the test runtime that we can run multiple integration tests in
// parallel. This just happens to be a convenient call site for all
......
......@@ -26,15 +26,7 @@ func TestIntegration_UpdateUser_Lang(t *testing.T) {
t.Fatalf("UpdateUser(): %v", err)
}
var user as.User
err = c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket("quattro@investici.org"),
},
Username: "quattro@investici.org",
},
}, &user)
user, err := c.getUser("quattro@investici.org")
if err != nil {
t.Fatalf("GetUser(): %v", err)
}
......@@ -44,19 +36,11 @@ func TestIntegration_UpdateUser_Lang(t *testing.T) {
}
func countRegistrations(t *testing.T, c *testClient) (*as.User, int) {
var user as.User
err := c.request("/api/user/get", &as.GetUserRequest{
UserRequestBase: as.UserRequestBase{
RequestBase: as.RequestBase{
SSO: c.ssoTicket("quattro@investici.org"),
},
Username: "quattro@investici.org",
},
}, &user)
user, err := c.getUser("quattro@investici.org")
if err != nil {
t.Fatalf("GetUser(): %v", err)
}
return &user, len(user.U2FRegistrations)
return user, len(user.U2FRegistrations)
}
func TestIntegration_UpdateUser_U2F(t *testing.T) {
......
Supports Markdown
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