Refactor and rename the standard OAuth services
This commit is contained in:
parent
bee2551dc2
commit
4755d08677
6 changed files with 82 additions and 242 deletions
|
@ -218,50 +218,6 @@ class OAuthLoginTestCase(EndpointTestCase):
|
|||
self.invoke_oauth_tests('github_oauth_callback', 'github_oauth_attach', 'github',
|
||||
'someid', 'someusername')
|
||||
|
||||
def test_dex_oauth(self):
|
||||
# TODO(jschorr): Add tests for invalid and expired keys.
|
||||
|
||||
# Generate a public/private key pair for the OIDC transaction.
|
||||
private_key = RSA.generate(2048)
|
||||
jwk = RSAKey(key=private_key.publickey()).serialize()
|
||||
token = jwt.encode({
|
||||
'iss': 'https://oidcserver/',
|
||||
'aud': 'someclientid',
|
||||
'sub': 'someid',
|
||||
'exp': int(time.time()) + 60,
|
||||
'iat': int(time.time()),
|
||||
'nbf': int(time.time()),
|
||||
'email': 'someemail@example.com',
|
||||
'email_verified': True,
|
||||
}, private_key.exportKey('PEM'), 'RS256')
|
||||
|
||||
@urlmatch(netloc=r'oidcserver', path='/.well-known/openid-configuration')
|
||||
def wellknown_handler(url, _):
|
||||
return py_json.dumps({
|
||||
'authorization_endpoint': 'http://oidcserver/auth',
|
||||
'token_endpoint': 'http://oidcserver/token',
|
||||
'jwks_uri': 'http://oidcserver/keys',
|
||||
})
|
||||
|
||||
@urlmatch(netloc=r'oidcserver', path='/token')
|
||||
def account_handler(url, request):
|
||||
if request.body.find("code=somecode") > 0:
|
||||
return py_json.dumps({
|
||||
'access_token': token,
|
||||
})
|
||||
else:
|
||||
return {'status_code': 400, 'content': '{"message": "Invalid code"}'}
|
||||
|
||||
@urlmatch(netloc=r'oidcserver', path='/keys')
|
||||
def keys_handler(_, __):
|
||||
return py_json.dumps({
|
||||
"keys": [jwk],
|
||||
})
|
||||
|
||||
with HTTMock(wellknown_handler, account_handler, keys_handler):
|
||||
self.invoke_oauth_tests('dex_oauth_callback', 'dex_oauth_attach', 'dex',
|
||||
'someid', 'someemail')
|
||||
|
||||
|
||||
class WebEndpointTestCase(EndpointTestCase):
|
||||
def test_index(self):
|
||||
|
|
Reference in a new issue