Auth: Convert SetDefaultOrgHook to PostLoginHook (#85649)

* Convert SetDefaultOrgHook to PostLoginHook
This commit is contained in:
Misi
2024-04-05 16:03:51 +02:00
committed by GitHub
parent 734d0111cb
commit 8796d2d307
4 changed files with 22 additions and 21 deletions
@@ -134,8 +134,7 @@ func TestOrgSync_SetDefaultOrgHook(t *testing.T) {
defaultOrgSetting int64
identity *authn.Identity
setupMock func(*usertest.MockService, *orgtest.FakeOrgService)
wantErr bool
inputErr error
}{
{
name: "should set default org",
@@ -157,6 +156,12 @@ func TestOrgSync_SetDefaultOrgHook(t *testing.T) {
defaultOrgSetting: -1,
identity: nil,
},
{
name: "should skip setting the default org when input err is not nil",
defaultOrgSetting: 2,
identity: &authn.Identity{ID: "user:1"},
inputErr: fmt.Errorf("error"),
},
{
name: "should skip setting the default org when identity is not a user",
defaultOrgSetting: 2,
@@ -181,13 +186,12 @@ func TestOrgSync_SetDefaultOrgHook(t *testing.T) {
},
},
{
name: "should return error when the user org update was unsuccessful",
name: "should skip the hook when the user org update was unsuccessful",
defaultOrgSetting: 2,
identity: &authn.Identity{ID: "user:1"},
setupMock: func(userService *usertest.MockService, orgService *orgtest.FakeOrgService) {
userService.On("SetUsingOrg", mock.Anything, mock.Anything).Return(fmt.Errorf("error"))
},
wantErr: true,
},
}
for _, tt := range testCases {
@@ -214,9 +218,9 @@ func TestOrgSync_SetDefaultOrgHook(t *testing.T) {
cfg: cfg,
}
if err := s.SetDefaultOrgHook(context.Background(), tt.identity, nil); (err != nil) != tt.wantErr {
t.Errorf("OrgSync.SetDefaultOrgHook() error = %v, wantErr %v", err, tt.wantErr)
}
s.SetDefaultOrgHook(context.Background(), tt.identity, nil, tt.inputErr)
userService.AssertExpectations(t)
})
}
}