Skip to content

Commit

Permalink
msal-node Device Code flow unit test - replaced sinon with jest (#7285)
Browse files Browse the repository at this point in the history
All sinon functionality in msal-node's device code flow unit test file
has been replaced with jest.

Sinon is no longer a dependency of msal-node.
  • Loading branch information
Robbie-Microsoft authored Sep 11, 2024
1 parent 1883b5e commit 22d3070
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 453 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Eliminated sinon from msal-node's device code unit tests and from msal-node's package.json #7285",
"packageName": "@azure/msal-node",
"email": "[email protected]",
"dependentChangeType": "none"
}
2 changes: 0 additions & 2 deletions lib/msal-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@
"@types/jest": "^29.5.0",
"@types/jsonwebtoken": "^9.0.1",
"@types/node": "^20.3.1",
"@types/sinon": "^7.5.0",
"@types/uuid": "^7.0.0",
"eslint-config-msal": "file:../../shared-configs/eslint-config-msal",
"jest": "^29.5.0",
"prettier": "2.8.7",
"rollup": "^3.20.1",
"sinon": "^7.5.0",
"ts-jest": "^29.1.0",
"tslib": "^1.10.0",
"typescript": "^4.9.5",
Expand Down
59 changes: 37 additions & 22 deletions lib/msal-node/test/client/ClientTestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
} from "@azure/msal-common";
import {
AUTHENTICATION_RESULT,
DEVICE_CODE_RESPONSE,
ID_TOKEN_CLAIMS,
RANDOM_TEST_GUID,
TEST_CONFIG,
Expand Down Expand Up @@ -430,25 +431,27 @@ export class ClientTestUtils {
}

interface checks {
dstsScope?: boolean | undefined;
graphScope?: boolean | undefined;
clientId?: boolean | undefined;
grantType?: string | undefined;
clientSecret?: boolean | undefined;
clientSku?: boolean | undefined;
clientVersion?: boolean | undefined;
clientOs?: boolean | undefined;
clientCpu?: boolean | undefined;
appName?: boolean | undefined;
appVersion?: boolean | undefined;
msLibraryCapability?: boolean | undefined;
claims?: boolean | undefined;
testConfigAssertion?: boolean | undefined;
testRequestAssertion?: boolean | undefined;
testAssertionType?: boolean | undefined;
responseType?: boolean | undefined;
username?: string | undefined;
password?: string | undefined;
dstsScope?: boolean;
graphScope?: boolean;
clientId?: boolean;
grantType?: string;
clientSecret?: boolean;
clientSku?: boolean;
clientVersion?: boolean;
clientOs?: boolean;
clientCpu?: boolean;
appName?: boolean;
appVersion?: boolean;
msLibraryCapability?: boolean;
claims?: boolean;
testConfigAssertion?: boolean;
testRequestAssertion?: boolean;
testAssertionType?: boolean;
responseType?: boolean;
username?: string;
password?: string;
deviceCode?: boolean;
queryString?: boolean;
}

export const checkMockedNetworkRequest = (
Expand Down Expand Up @@ -477,7 +480,7 @@ export const checkMockedNetworkRequest = (
).toBe(checks.clientId);
}

if (checks.grantType !== undefined) {
if (checks.grantType) {
expect(
returnVal.includes(
`${AADServerParamKeys.GRANT_TYPE}=${checks.grantType}`
Expand Down Expand Up @@ -597,21 +600,33 @@ export const checkMockedNetworkRequest = (
).toBe(checks.responseType);
}

if (checks.username !== undefined) {
if (checks.username) {
expect(
returnVal.includes(
`${PasswordGrantConstants.username}=${checks.username}`
)
).toBe(true);
}

if (checks.password !== undefined) {
if (checks.password) {
expect(
returnVal.includes(
`${PasswordGrantConstants.password}=${checks.password}`
)
).toBe(true);
}

if (checks.deviceCode) {
expect(returnVal.includes(DEVICE_CODE_RESPONSE.deviceCode)).toBe(true);
}

if (checks.queryString) {
expect(
returnVal.includes(
`${TEST_CONFIG.DEFAULT_GRAPH_SCOPE}%20${Constants.OPENID_SCOPE}%20${Constants.PROFILE_SCOPE}%20${Constants.OFFLINE_ACCESS_SCOPE}`
)
).toBe(true);
}
};

export const getClientAssertionCallback = (
Expand Down
Loading

0 comments on commit 22d3070

Please sign in to comment.