Browse Source

ignore dup user err upon login w/ DisableAuth=true

Mike 2 years ago
parent
commit
7a93404066
3 changed files with 69 additions and 8 deletions
  1. 3 1
      foodgroup/auth.go
  2. 63 4
      foodgroup/auth_test.go
  3. 3 3
      foodgroup/test_helpers.go

+ 3 - 1
foodgroup/auth.go

@@ -183,7 +183,9 @@ func (s AuthService) BUCPLoginRequest(bodyIn wire.SNAC_0x17_0x02_BUCPLoginReques
 			return wire.SNACMessage{}, err
 		}
 		if err := s.userManager.InsertUser(user); err != nil {
-			return wire.SNACMessage{}, err
+			if !errors.Is(err, state.ErrDupUser) {
+				return wire.SNACMessage{}, err
+			}
 		}
 		loginOK = true
 	}

+ 63 - 4
foodgroup/auth_test.go

@@ -112,7 +112,7 @@ func TestAuthService_BUCPLoginRequest(t *testing.T) {
 							result:     nil,
 						},
 					},
-					upsertUserParams: upsertUserParams{
+					insertUserParams: insertUserParams{
 						{
 							user: user,
 						},
@@ -170,7 +170,7 @@ func TestAuthService_BUCPLoginRequest(t *testing.T) {
 							result:     &user,
 						},
 					},
-					upsertUserParams: upsertUserParams{
+					insertUserParams: insertUserParams{
 						{
 							user: user,
 						},
@@ -205,6 +205,65 @@ func TestAuthService_BUCPLoginRequest(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "user logs in with invalid password--account already exists and logged in successfully",
+			cfg: config.Config{
+				OSCARHost:   "127.0.0.1",
+				BOSPort:     1234,
+				DisableAuth: true,
+			},
+			inputSNAC: wire.SNAC_0x17_0x02_BUCPLoginRequest{
+				TLVRestBlock: wire.TLVRestBlock{
+					TLVList: wire.TLVList{
+						wire.NewTLV(wire.TLVPasswordHash, []byte("bad-password-hash")),
+						wire.NewTLV(wire.TLVScreenName, user.ScreenName),
+					},
+				},
+			},
+			mockParams: mockParams{
+				userManagerParams: userManagerParams{
+					getUserParams: getUserParams{
+						{
+							screenName: user.ScreenName,
+							result:     &user,
+						},
+					},
+					insertUserParams: insertUserParams{
+						{
+							user: user,
+							err:  state.ErrDupUser,
+						},
+					},
+				},
+				sessionManagerParams: sessionManagerParams{
+					addSessionParams: addSessionParams{
+						{
+							sessID:     userSession.ID(),
+							screenName: user.ScreenName,
+							result:     userSession,
+						},
+					},
+				},
+			},
+			newUserFn: func(screenName string) (state.User, error) {
+				return user, nil
+			},
+			expectOutput: wire.SNACMessage{
+				Frame: wire.SNACFrame{
+					FoodGroup: wire.BUCP,
+					SubGroup:  wire.BUCPLoginResponse,
+				},
+				Body: wire.SNAC_0x17_0x03_BUCPLoginResponse{
+					TLVRestBlock: wire.TLVRestBlock{
+						TLVList: wire.TLVList{
+							wire.NewTLV(wire.TLVScreenName, user.ScreenName),
+							wire.NewTLV(wire.TLVReconnectHere, "127.0.0.1:1234"),
+							wire.NewTLV(wire.TLVAuthorizationCookie, sessUUID.String()),
+						},
+					},
+				},
+			},
+		},
 		{
 			name: "user provides invalid password--account creation fails due to user creation runtime error",
 			cfg: config.Config{
@@ -254,7 +313,7 @@ func TestAuthService_BUCPLoginRequest(t *testing.T) {
 							result:     &user,
 						},
 					},
-					upsertUserParams: upsertUserParams{
+					insertUserParams: insertUserParams{
 						{
 							user: user,
 							err:  io.EOF,
@@ -338,7 +397,7 @@ func TestAuthService_BUCPLoginRequest(t *testing.T) {
 					User(params.screenName).
 					Return(params.result, params.err)
 			}
-			for _, params := range tc.mockParams.upsertUserParams {
+			for _, params := range tc.mockParams.insertUserParams {
 				userManager.EXPECT().
 					InsertUser(params.user).
 					Return(params.err)

+ 3 - 3
foodgroup/test_helpers.go

@@ -61,7 +61,7 @@ type chatRegistryRetrieveParams struct {
 // UserManager methods
 type userManagerParams struct {
 	getUserParams
-	upsertUserParams
+	insertUserParams
 }
 
 // getUserParams is the list of parameters passed at the mock
@@ -72,9 +72,9 @@ type getUserParams []struct {
 	err        error
 }
 
-// upsertUserParams is the list of parameters passed at the mock
+// insertUserParams is the list of parameters passed at the mock
 // UserManager.UpsertUser call site
-type upsertUserParams []struct {
+type insertUserParams []struct {
 	user state.User
 	err  error
 }