E2E test that checks OpenID Connect Implicit Flow.
(t *testing.T)
| 1002 | |
| 1003 | // E2E test that checks OpenID Connect Implicit Flow. |
| 1004 | func TestOpenIDConnectImplicitFlow(t *testing.T) { |
| 1005 | type test struct { |
| 1006 | name string |
| 1007 | providers auth.OIDCProviderMap |
| 1008 | defaultProvider string |
| 1009 | expectedError forceError |
| 1010 | requireExistingUser bool |
| 1011 | } |
| 1012 | tests := []test{ |
| 1013 | { |
| 1014 | // Successful new user authentication against single provider |
| 1015 | // when auto registration is enabled. |
| 1016 | name: "successful user registration against single provider", |
| 1017 | providers: auth.OIDCProviderMap{ |
| 1018 | "foo": mockProviderWith("foo", mockProviderRegister{}, mockProviderUserPrefix{"foo"}), |
| 1019 | }, |
| 1020 | defaultProvider: "foo", |
| 1021 | }, { |
| 1022 | // Unsuccessful new user authentication against single provider |
| 1023 | // when auto registration is NOT enabled. |
| 1024 | name: "unsuccessful user registration against single provider", |
| 1025 | providers: auth.OIDCProviderMap{ |
| 1026 | "foo": mockProvider("foo"), |
| 1027 | }, |
| 1028 | defaultProvider: "foo", |
| 1029 | expectedError: forceError{ |
| 1030 | expectedErrorCode: http.StatusUnauthorized, |
| 1031 | expectedErrorMessage: ErrInvalidLogin.Message, |
| 1032 | }, |
| 1033 | }, { |
| 1034 | name: "successful registered user authentication against single provider", |
| 1035 | providers: auth.OIDCProviderMap{ |
| 1036 | "foo": mockProviderWith("foo", mockProviderUserPrefix{"foo"}), |
| 1037 | }, |
| 1038 | defaultProvider: "foo", |
| 1039 | requireExistingUser: true, |
| 1040 | }, |
| 1041 | } |
| 1042 | for _, tc := range tests { |
| 1043 | t.Run(tc.name, func(t *testing.T) { |
| 1044 | mockAuthServer, err := newMockAuthServer() |
| 1045 | require.NoError(t, err, "Error creating mock oauth2 server") |
| 1046 | mockAuthServer.Start() |
| 1047 | defer mockAuthServer.Shutdown() |
| 1048 | mockAuthServer.options.issuer = mockAuthServer.URL + "/" + tc.defaultProvider |
| 1049 | refreshProviderConfig(tc.providers, mockAuthServer.URL) |
| 1050 | |
| 1051 | opts := auth.OIDCOptions{Providers: tc.providers, DefaultProvider: &tc.defaultProvider} |
| 1052 | restTesterConfig := RestTesterConfig{DatabaseConfig: &DatabaseConfig{DbConfig: DbConfig{OIDCConfig: &opts}}} |
| 1053 | restTester := NewRestTester(t, &restTesterConfig) |
| 1054 | defer restTester.Close() |
| 1055 | |
| 1056 | // Create the user first if the test requires a registered user. |
| 1057 | if tc.requireExistingUser { |
| 1058 | createUser(t, restTester, "foo_noah") |
| 1059 | } |
| 1060 | |
| 1061 | mockSyncGateway := httptest.NewServer(restTester.TestPublicHandler()) |
nothing calls this directly
no test coverage detected