-
Notifications
You must be signed in to change notification settings - Fork 160
fix(jans-cedarling): fix benchmarks to actually work #12923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e1eac24
fix(jans-cedarling): update mock server usage in authz_authorize_benc…
dagregi 32bfc51
feat(jans-cedarling): add validation check before running benchmarks
dagregi f22e1c4
chore(jans-cedarling): add exclusion threshold for problematic benchmark
dagregi 14d991d
Merge branch 'main' into jans-cedarling-12900
olehbozhok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,31 @@ use tokio::runtime::Runtime; | |
|
|
||
| const POLICY_STORE: &str = include_str!("../../test_files/policy-store_ok.yaml"); | ||
|
|
||
| // Validates that the cedarling instance actually works before benchmarking. | ||
| async fn validate_cedarling_works(cedarling: &Cedarling, request: &Request) { | ||
| let result = cedarling | ||
| .authorize(request.clone()) | ||
| .await | ||
| .expect("authorization call failed"); | ||
|
|
||
| let is_allowed = match result.cedar_decision() { | ||
| cedar_policy::Decision::Allow => true, | ||
| cedar_policy::Decision::Deny => false, | ||
| }; | ||
|
|
||
| assert!(is_allowed, "got invalid authorization result"); | ||
| } | ||
|
|
||
| fn without_jwt_validation_benchmark(c: &mut Criterion) { | ||
| let runtime = Runtime::new().expect("init tokio runtime"); | ||
|
|
||
| let cedarling = runtime | ||
| .block_on(prepare_cedarling_without_jwt_validation()) | ||
| .expect("should initialize Cedarling"); | ||
|
|
||
| let request = | ||
| prepare_cedarling_request_for_without_jwt_validation().expect("should prepare r:equest"); | ||
| let request = prepare_cedarling_request_for_without_jwt_validation(); | ||
|
|
||
| runtime.block_on(validate_cedarling_works(&cedarling, &request)); | ||
|
|
||
| c.bench_with_input( | ||
| BenchmarkId::new("authz_authorize_without_jwt_validation", "tokio runtime"), | ||
|
|
@@ -53,8 +69,10 @@ fn with_jwt_validation_hs256_benchmark(c: &mut Criterion) { | |
| )) | ||
| .expect("should initialize Cedarling"); | ||
|
|
||
| let request = prepare_cedarling_request_for_with_jwt_validation(mock1.keys) | ||
| .expect("should prepare request"); | ||
| let request = | ||
| prepare_cedarling_request_for_with_jwt_validation(&mock1.keys, &mock1.base_idp_url); | ||
|
|
||
| runtime.block_on(validate_cedarling_works(&cedarling, &request)); | ||
|
|
||
| c.bench_with_input( | ||
| BenchmarkId::new("authz_authorize_with_jwt_validation_hs256", "tokio runtime"), | ||
|
|
@@ -163,15 +181,14 @@ async fn prepare_cedarling_with_jwt_validation( | |
| Cedarling::new(&bootstrap_config).await | ||
| } | ||
|
|
||
| pub fn prepare_cedarling_request_for_without_jwt_validation() -> Result<Request, serde_json::Error> | ||
| { | ||
| pub fn prepare_cedarling_request_for_without_jwt_validation() -> Request { | ||
| Request::deserialize(serde_json::json!( | ||
| { | ||
| "tokens": { | ||
| "access_token": generate_token_using_claims(json!({ | ||
| "sub": "boG8dfc5MKTn37o7gsdCeyqL8LpWQtgoO41m1KZwdq0", | ||
| "code": "bf1934f6-3905-420a-8299-6b2e3ffddd6e", | ||
| "iss": "https://admin-ui-test.gluu.org", | ||
| "iss": "https://test.jans.org", | ||
| "token_type": "Bearer", | ||
| "client_id": "5b4487c4-8db1-409d-a653-f907b8094039", | ||
| "aud": "5b4487c4-8db1-409d-a653-f907b8094039", | ||
|
|
@@ -201,7 +218,7 @@ pub fn prepare_cedarling_request_for_without_jwt_validation() -> Result<Request, | |
| "exp": 1724835859, | ||
| "iat": 1724832259, | ||
| "sub": "boG8dfc5MKTn37o7gsdCeyqL8LpWQtgoO41m1KZwdq0", | ||
| "iss": "https://admin-ui-test.gluu.org", | ||
| "iss": "https://test.jans.org", | ||
| "jti": "sk3T40NYSYuk5saHZNpkZw", | ||
| "nonce": "c3872af9-a0f5-4c3f-a1af-f9d0e8846e81", | ||
| "sid": "6a7fe50a-d810-454d-be5d-549d29595a09", | ||
|
|
@@ -222,7 +239,7 @@ pub fn prepare_cedarling_request_for_without_jwt_validation() -> Result<Request, | |
| "email": "[email protected]", | ||
| "username": "UserNameExample", | ||
| "sub": "boG8dfc5MKTn37o7gsdCeyqL8LpWQtgoO41m1KZwdq0", | ||
| "iss": "https://admin-ui-test.gluu.org", | ||
| "iss": "https://test.jans.org", | ||
| "given_name": "Admin", | ||
| "middle_name": "Admin", | ||
| "inum": "8d1cde6a-1447-4766-b3c8-16663e13b458", | ||
|
|
@@ -251,18 +268,20 @@ pub fn prepare_cedarling_request_for_without_jwt_validation() -> Result<Request, | |
| "context": {}, | ||
| } | ||
| )) | ||
| .expect("should build request") | ||
| } | ||
|
|
||
| pub fn prepare_cedarling_request_for_with_jwt_validation( | ||
| keys1: KeyPair, | ||
| ) -> Result<Request, serde_json::Error> { | ||
| keys1: &KeyPair, | ||
| issuer_url: &str, | ||
| ) -> Request { | ||
| Request::deserialize(serde_json::json!( | ||
| { | ||
| "tokens": { | ||
| "access_token": generate_token_using_claims_and_keypair(&json!({ | ||
| "sub": "boG8dfc5MKTn37o7gsdCeyqL8LpWQtgoO41m1KZwdq0", | ||
| "code": "bf1934f6-3905-420a-8299-6b2e3ffddd6e", | ||
| "iss": "https://admin-ui-test.gluu.org", | ||
| "iss": issuer_url, | ||
| "token_type": "Bearer", | ||
| "client_id": "5b4487c4-8db1-409d-a653-f907b8094039", | ||
| "aud": "5b4487c4-8db1-409d-a653-f907b8094039", | ||
|
|
@@ -284,15 +303,15 @@ pub fn prepare_cedarling_request_for_with_jwt_validation( | |
| "uri": "https://admin-ui-test.gluu.org/jans-auth/restv1/status_list" | ||
| } | ||
| } | ||
| }), &keys1), | ||
| }), keys1), | ||
| "id_token": generate_token_using_claims_and_keypair(&json!({ | ||
| "acr": "basic", | ||
| "amr": "10", | ||
| "aud": "5b4487c4-8db1-409d-a653-f907b8094039", | ||
| "exp": 1724835859, | ||
| "iat": 1724832259, | ||
| "sub": "boG8dfc5MKTn37o7gsdCeyqL8LpWQtgoO41m1KZwdq0", | ||
| "iss": "https://admin-ui-test.gluu.org", | ||
| "iss": issuer_url, | ||
| "jti": "sk3T40NYSYuk5saHZNpkZw", | ||
| "nonce": "c3872af9-a0f5-4c3f-a1af-f9d0e8846e81", | ||
| "sid": "6a7fe50a-d810-454d-be5d-549d29595a09", | ||
|
|
@@ -307,13 +326,13 @@ pub fn prepare_cedarling_request_for_with_jwt_validation( | |
| } | ||
| }, | ||
| "role":"Admin" | ||
| }),&keys1), | ||
| }), keys1), | ||
| "userinfo_token": generate_token_using_claims_and_keypair(&json!({ | ||
| "country": "US", | ||
| "email": "[email protected]", | ||
| "username": "UserNameExample", | ||
| "sub": "boG8dfc5MKTn37o7gsdCeyqL8LpWQtgoO41m1KZwdq0", | ||
| "iss": "https://admin-ui-test.gluu.org", | ||
| "iss": issuer_url, | ||
| "given_name": "Admin", | ||
| "middle_name": "Admin", | ||
| "inum": "8d1cde6a-1447-4766-b3c8-16663e13b458", | ||
|
|
@@ -328,7 +347,7 @@ pub fn prepare_cedarling_request_for_with_jwt_validation( | |
| "api-admin" | ||
| ], | ||
| "exp": 1724945978 | ||
| }), &keys1), | ||
| }), keys1), | ||
| }, | ||
| "action": "Jans::Action::\"Update\"", | ||
| "resource": { | ||
|
|
@@ -342,4 +361,5 @@ pub fn prepare_cedarling_request_for_with_jwt_validation( | |
| "context": {}, | ||
| } | ||
| )) | ||
| .expect("should build request") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.