Skip to content
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

Added msal-node client-credential regression test #6276

Merged
merged 35 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1a1ac14
Added msal-node client-credential regression test
Robbie-Microsoft Jul 31, 2023
eeda597
modified client-credential.yml
Robbie-Microsoft Jul 31, 2023
d6ac2cd
modified client-credential.yml
Robbie-Microsoft Jul 31, 2023
4a303fb
modified client-credential.yml
Robbie-Microsoft Jul 31, 2023
3f40e16
modified client-credential.yml
Robbie-Microsoft Jul 31, 2023
72e01b7
added fake regression for testing github actions, will remove later
Robbie-Microsoft Jul 31, 2023
917e9c4
added sleep function for regression test
Robbie-Microsoft Jul 31, 2023
476f58e
removed fake regression
Robbie-Microsoft Jul 31, 2023
0af3b31
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 3, 2023
b327798
Testing minSamples on GitHub actions
Robbie-Microsoft Aug 3, 2023
5271450
reverted changes for testing. Added a minSamples value of 150
Robbie-Microsoft Aug 3, 2023
7231dda
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 8, 2023
4427feb
Added charts for gh-pages
Robbie-Microsoft Aug 8, 2023
af3472b
Added fake regression
Robbie-Microsoft Aug 8, 2023
9fdec9a
Removed fake regression
Robbie-Microsoft Aug 8, 2023
b8dab61
Finalized workflow file
Robbie-Microsoft Aug 8, 2023
32d7845
Implemented GitHub Feedback
Robbie-Microsoft Aug 9, 2023
58ba824
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 9, 2023
4d2f748
Testing push to gh-pages branch
Robbie-Microsoft Aug 9, 2023
6f77167
Removing testing that determined typedocs and performance data can bo…
Robbie-Microsoft Aug 9, 2023
9afa540
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 22, 2023
964dfda
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 23, 2023
6a06154
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 25, 2023
bcaba56
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 29, 2023
2166091
Added all confidential client devs to codeowners for confidential cli…
Robbie-Microsoft Aug 29, 2023
773d873
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 29, 2023
9875ec2
Renamed files. Removed code from .yml for testing purposes.
Robbie-Microsoft Aug 30, 2023
44e4fa9
Removed code from .yml that was for testing purposes
Robbie-Microsoft Aug 30, 2023
4ace75b
Implemented gitHub Feedback
Robbie-Microsoft Aug 30, 2023
f33cb63
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Aug 30, 2023
3ef6807
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Sep 5, 2023
72d0b06
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Sep 6, 2023
c39bd8b
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Sep 6, 2023
64b41f3
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Sep 11, 2023
345a21f
Merge branch 'dev' into client_credentials_regression_test
Robbie-Microsoft Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/client-credential.yml
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: msal-node client-credential Regression Test
on:
pull_request:
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved
types: [opened, reopened, synchronize, ready_for_review]
paths:
- "regression-tests/msal-node/client-credential/*"
- "lib/msal-node/**/*"
- "lib/msal-common/**/*"
- "!**.md"
- ".github/workflows/client-credential.yml"
merge_group:
types: [checks_requested]

permissions:
contents: write
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved

jobs:
benchmark:
name: Run msal-node client-credential Regression Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Run benchmark
run: cd regression-tests/msal-node/client-credential && npm install && node index.js | tee output.txt

- name: Download previous benchmark data
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark

- name: Store benchmark result
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved
uses: benchmark-action/github-action-benchmark@v1
with:
name: msal-node client-credential Regression Test
tool: 'benchmarkjs'
output-file-path: regression-tests/msal-node/client-credential/output.txt
external-data-json-path: ./cache/client-credential-benchmark-data.json
github-token: ${{ secrets.GITHUB_TOKEN }}
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '10%'
Robbie-Microsoft marked this conversation as resolved.
Show resolved Hide resolved
comment-on-alert: true
fail-on-alert: false
alert-comment-cc-users: '@bgavrilMS @robbie-microsoft'
94 changes: 94 additions & 0 deletions regression-tests/msal-node/Constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

const NetworkUtils = class NetworkUtils {
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
static getNetworkResponse(headers, body, statusCode) {
return {
headers: headers,
body: body,
status: statusCode,
};
}
};

const DEFAULT_OPENID_CONFIG_RESPONSE = {
headers: {},
status: 200,
body: {
token_endpoint:
"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token",
token_endpoint_auth_methods_supported: [
"client_secret_post",
"private_key_jwt",
"client_secret_basic",
],
jwks_uri:
"https://login.microsoftonline.com/{tenant}/discovery/v2.0/keys",
response_modes_supported: ["query", "fragment", "form_post"],
subject_types_supported: ["pairwise"],
id_token_signing_alg_values_supported: ["RS256"],
response_types_supported: [
"code",
"id_token",
"code id_token",
"id_token token",
],
scopes_supported: ["openid", "profile", "email", "offline_access"],
issuer: "https://login.microsoftonline.com/{tenant}/v2.0",
request_uri_parameter_supported: false,
userinfo_endpoint: "https://graph.microsoft.com/oidc/userinfo",
authorization_endpoint:
"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize",
http_logout_supported: true,
frontchannel_logout_supported: true,
end_session_endpoint:
"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/logout",
claims_supported: [
"sub",
"iss",
"cloud_instance_name",
"cloud_instance_host_name",
"cloud_graph_host_name",
"msgraph_host",
"aud",
"exp",
"iat",
"auth_time",
"acr",
"nonce",
"preferred_username",
"name",
"tid",
"ver",
"at_hash",
"c_hash",
"email",
],
tenant_region_scope: null,
cloud_instance_name: "microsoftonline.com",
cloud_graph_host_name: "graph.windows.net",
msgraph_host: "graph.microsoft.com",
rbac_url: "https://pas.windows.net",
},
};

const CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT = {
headers: {},
status: 200,
body: {
token_type: "Bearer",
expires_in: 3599,
ext_expires_in: 3599,
refresh_in: 3598 / 2,
access_token: "thisIs.an.accessT0ken",
},
};

module.exports = {
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT,
DEFAULT_OPENID_CONFIG_RESPONSE,
NetworkUtils,
};
1 change: 1 addition & 0 deletions regression-tests/msal-node/client-credential/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
87 changes: 87 additions & 0 deletions regression-tests/msal-node/client-credential/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/

/* eslint-disable @typescript-eslint/no-unused-vars */

import benchmark from "benchmark";
import * as msal from "@azure/msal-node";
import {
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT,
DEFAULT_OPENID_CONFIG_RESPONSE,
NetworkUtils,
} from "../Constants.js";

const clientConfig = {
auth: {
clientId: "client_id",
authority: "https://login.microsoftonline.com/tenant_id",
knownAuthorities: ["https://login.microsoftonline.com/tenant_id"],
clientSecret: "client_secret",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should probably also do one for certificates. maybe in another PR.

},
system: {
networkClient: new class CustomHttpClient {
sendGetRequestAsync(url, options, cancellationToken) {
return new Promise((resolve, reject) => {
const networkResponse = NetworkUtils.getNetworkResponse(
DEFAULT_OPENID_CONFIG_RESPONSE.headers,
DEFAULT_OPENID_CONFIG_RESPONSE.body,
DEFAULT_OPENID_CONFIG_RESPONSE.status,
);
resolve(networkResponse);
});
}
sendPostRequestAsync(url, options) {
return new Promise((resolve, _reject) => {
const networkResponse = NetworkUtils.getNetworkResponse(
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT.headers,
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT.body,
CONFIDENTIAL_CLIENT_AUTHENTICATION_RESULT.status,
);
resolve(networkResponse);
});
}
}
},
};

const NUM_CACHE_ITEMS = 10;

const confidentialClientApplication = new msal.ConfidentialClientApplication(clientConfig);
const firstResourceRequest = {
scopes: ["resource-1/.default"],
};
const lastResourceRequest = {
scopes: [`resource-${NUM_CACHE_ITEMS}/.default`],
};

(async () => {
// pre populate the cache
for (let i = 1; i <= NUM_CACHE_ITEMS; i++) {
const request = {
scopes: [`resource-${i}/.default`],
};
await confidentialClientApplication.acquireTokenByClientCredential(request);
}

const suite = new benchmark.Suite();
suite
.add("ConfidentialClientApplication#acquireTokenByClientCredential-fromCache-resourceIsFirstItemInTheCache", {
"fn": async () => {
await confidentialClientApplication.acquireTokenByClientCredential(firstResourceRequest);
},
"minSamples": 150,
})
.add("ConfidentialClientApplication#acquireTokenByClientCredential-fromCache-resourceIsLastItemInTheCache", {
"fn": async () => {
await confidentialClientApplication.acquireTokenByClientCredential(lastResourceRequest);
},
"minSamples": 150,
})
.on("cycle", (event) => {
// eslint-disable-next-line no-console
console.log(String(event.target));
})
.run({ "async": true });
})();
Loading
Loading