Exemplo n.º 1
0
 def test_request_auth_code(self):
     """test request param"""
     provider = OAuth2Provider.objects.create(
         name="test",
         client_id=generate_id(),
         client_secret=generate_key(),
         authorization_flow=create_test_flow(),
         redirect_uris="http://testserver",
         signing_key=create_test_cert(),
     )
     header = b64encode(f"{provider.client_id}:{provider.client_secret}".
                        encode()).decode()
     user = create_test_admin_user()
     code = AuthorizationCode.objects.create(code="foobar",
                                             provider=provider,
                                             user=user)
     request = self.factory.post(
         "/",
         data={
             "grant_type": GRANT_TYPE_AUTHORIZATION_CODE,
             "code": code.code,
             "redirect_uri": "http://testserver",
         },
         HTTP_AUTHORIZATION=f"Basic {header}",
     )
     params = TokenParams.parse(request, provider, provider.client_id,
                                provider.client_secret)
     self.assertEqual(params.provider, provider)
     with self.assertRaises(TokenError):
         TokenParams.parse(request, provider, provider.client_id,
                           generate_key())
Exemplo n.º 2
0
 def test_request_refresh_token(self):
     """test request param"""
     provider = OAuth2Provider.objects.create(
         name="test",
         client_id=generate_id(),
         client_secret=generate_key(),
         authorization_flow=create_test_flow(),
         redirect_uris="http://local.invalid",
         signing_key=create_test_cert(),
     )
     header = b64encode(f"{provider.client_id}:{provider.client_secret}".
                        encode()).decode()
     user = create_test_admin_user()
     token: RefreshToken = RefreshToken.objects.create(
         provider=provider,
         user=user,
         refresh_token=generate_id(),
     )
     request = self.factory.post(
         "/",
         data={
             "grant_type": GRANT_TYPE_REFRESH_TOKEN,
             "refresh_token": token.refresh_token,
             "redirect_uri": "http://local.invalid",
         },
         HTTP_AUTHORIZATION=f"Basic {header}",
     )
     params = TokenParams.parse(request, provider, provider.client_id,
                                provider.client_secret)
     self.assertEqual(params.provider, provider)
Exemplo n.º 3
0
 def test_request_auth_code(self):
     """test request param"""
     provider = OAuth2Provider.objects.create(
         name="test",
         client_id=generate_client_id(),
         client_secret=generate_client_secret(),
         authorization_flow=Flow.objects.first(),
         redirect_uris="http://local.invalid",
     )
     header = b64encode(
         f"{provider.client_id}:{provider.client_secret}".encode()
     ).decode()
     user = User.objects.get(username="******")
     code = AuthorizationCode.objects.create(
         code="foobar", provider=provider, user=user
     )
     request = self.factory.post(
         "/",
         data={
             "grant_type": GRANT_TYPE_AUTHORIZATION_CODE,
             "code": code.code,
             "redirect_uri": "http://local.invalid",
         },
         HTTP_AUTHORIZATION=f"Basic {header}",
     )
     params = TokenParams.from_request(request)
     self.assertEqual(params.provider, provider)