feat: add idpyoidc server initialization
This commit is contained in:
parent
02b75a3eca
commit
2426e0675c
2 changed files with 192 additions and 0 deletions
56
tests/test_oidc/test_provider.py
Normal file
56
tests/test_oidc/test_provider.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi_oidc_op.config import Settings
|
||||
from fastapi_oidc_op.oidc.provider import create_oidc_server
|
||||
|
||||
|
||||
def test_create_server_has_endpoints() -> None:
|
||||
key_path = Path("test_keys_provider")
|
||||
key_path.mkdir(exist_ok=True)
|
||||
try:
|
||||
settings = Settings(issuer="http://localhost:8000", sqlite_path=":memory:", signing_key_path=str(key_path))
|
||||
server = create_oidc_server(settings)
|
||||
assert "authorization" in server.endpoint
|
||||
assert "token" in server.endpoint
|
||||
assert "userinfo" in server.endpoint
|
||||
assert "provider_config" in server.endpoint
|
||||
finally:
|
||||
shutil.rmtree(key_path, ignore_errors=True)
|
||||
|
||||
|
||||
def test_create_server_has_issuer() -> None:
|
||||
key_path = Path("test_keys_issuer")
|
||||
key_path.mkdir(exist_ok=True)
|
||||
try:
|
||||
settings = Settings(issuer="http://localhost:8000", sqlite_path=":memory:", signing_key_path=str(key_path))
|
||||
server = create_oidc_server(settings)
|
||||
assert server.context.issuer == "http://localhost:8000"
|
||||
finally:
|
||||
shutil.rmtree(key_path, ignore_errors=True)
|
||||
|
||||
|
||||
def test_create_server_jwks_available() -> None:
|
||||
key_path = Path("test_keys_jwks")
|
||||
key_path.mkdir(exist_ok=True)
|
||||
try:
|
||||
settings = Settings(issuer="http://localhost:8000", sqlite_path=":memory:", signing_key_path=str(key_path))
|
||||
server = create_oidc_server(settings)
|
||||
keys = server.keyjar.export_jwks()
|
||||
assert "keys" in keys
|
||||
assert len(keys["keys"]) > 0
|
||||
finally:
|
||||
shutil.rmtree(key_path, ignore_errors=True)
|
||||
|
||||
|
||||
def test_create_server_userinfo_is_porchlight() -> None:
|
||||
key_path = Path("test_keys_userinfo")
|
||||
key_path.mkdir(exist_ok=True)
|
||||
try:
|
||||
settings = Settings(issuer="http://localhost:8000", sqlite_path=":memory:", signing_key_path=str(key_path))
|
||||
server = create_oidc_server(settings)
|
||||
from fastapi_oidc_op.oidc.claims import PorchlightUserInfo
|
||||
|
||||
assert isinstance(server.context.userinfo, PorchlightUserInfo)
|
||||
finally:
|
||||
shutil.rmtree(key_path, ignore_errors=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue