def test_invalid_redirect_uri(self):
     """test missing/invalid redirect URI"""
     OAuth2Provider.objects.create(
         name="test",
         client_id="test",
         authorization_flow=create_test_flow(),
         redirect_uris="http://local.invalid",
     )
     with self.assertRaises(RedirectUriError):
         request = self.factory.get("/",
                                    data={
                                        "response_type": "code",
                                        "client_id": "test"
                                    })
         OAuthAuthorizationParams.from_request(request)
     with self.assertRaises(RedirectUriError):
         request = self.factory.get(
             "/",
             data={
                 "response_type": "code",
                 "client_id": "test",
                 "redirect_uri": "http://localhost",
             },
         )
         OAuthAuthorizationParams.from_request(request)
Exemple #2
0
 def test_invalid_client_id(self):
     """Test invalid client ID"""
     with self.assertRaises(ClientIdError):
         request = self.factory.get(
             "/", data={"response_type": "code", "client_id": "invalid"}
         )
         OAuthAuthorizationParams.from_request(request)
Exemple #3
0
 def test_request(self):
     """test request param"""
     OAuth2Provider.objects.create(
         name="test",
         client_id="test",
         authorization_flow=Flow.objects.first(),
         redirect_uris="http://local.invalid",
     )
     with self.assertRaises(AuthorizeError):
         request = self.factory.get(
             "/",
             data={
                 "response_type": "code",
                 "client_id": "test",
                 "redirect_uri": "http://local.invalid",
                 "request": "foo",
             },
         )
         OAuthAuthorizationParams.from_request(request)
 def test_empty_redirect_uri(self):
     """test empty redirect URI (configure in provider)"""
     OAuth2Provider.objects.create(
         name="test",
         client_id="test",
         authorization_flow=create_test_flow(),
     )
     with self.assertRaises(RedirectUriError):
         request = self.factory.get("/",
                                    data={
                                        "response_type": "code",
                                        "client_id": "test"
                                    })
         OAuthAuthorizationParams.from_request(request)
     request = self.factory.get(
         "/",
         data={
             "response_type": "code",
             "client_id": "test",
             "redirect_uri": "http://localhost",
         },
     )
     OAuthAuthorizationParams.from_request(request)
 def test_invalid_grant_type(self):
     """Test with invalid grant type"""
     with self.assertRaises(AuthorizeError):
         request = self.factory.get("/", data={"response_type": "invalid"})
         OAuthAuthorizationParams.from_request(request)
 def test_response_type(self):
     """test response_type"""
     OAuth2Provider.objects.create(
         name="test",
         client_id="test",
         authorization_flow=create_test_flow(),
         redirect_uris="http://local.invalid",
     )
     request = self.factory.get(
         "/",
         data={
             "response_type": "code",
             "client_id": "test",
             "redirect_uri": "http://local.invalid",
         },
     )
     self.assertEqual(
         OAuthAuthorizationParams.from_request(request).grant_type,
         GrantTypes.AUTHORIZATION_CODE,
     )
     request = self.factory.get(
         "/",
         data={
             "response_type": "id_token",
             "client_id": "test",
             "redirect_uri": "http://local.invalid",
             "scope": "openid",
             "state": "foo",
         },
     )
     self.assertEqual(
         OAuthAuthorizationParams.from_request(request).grant_type,
         GrantTypes.IMPLICIT,
     )
     # Implicit without openid scope
     with self.assertRaises(AuthorizeError):
         request = self.factory.get(
             "/",
             data={
                 "response_type": "id_token",
                 "client_id": "test",
                 "redirect_uri": "http://local.invalid",
                 "state": "foo",
             },
         )
         self.assertEqual(
             OAuthAuthorizationParams.from_request(request).grant_type,
             GrantTypes.IMPLICIT,
         )
     request = self.factory.get(
         "/",
         data={
             "response_type": "code token",
             "client_id": "test",
             "redirect_uri": "http://local.invalid",
             "scope": "openid",
             "state": "foo",
         },
     )
     self.assertEqual(
         OAuthAuthorizationParams.from_request(request).grant_type,
         GrantTypes.HYBRID)
     with self.assertRaises(AuthorizeError):
         request = self.factory.get(
             "/",
             data={
                 "response_type": "invalid",
                 "client_id": "test",
                 "redirect_uri": "http://local.invalid",
             },
         )
         OAuthAuthorizationParams.from_request(request)