@azure/arm-resources 5.2.1-alpha.20250113.1 → 5.2.1-alpha.20250114.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cae_mock_test.d.ts","sourceRoot":"","sources":["../../test/cae_mock_test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { __asyncValues, __awaiter } from "tslib";
|
|
2
|
+
import { assert } from "chai";
|
|
3
|
+
import { ResourceManagementClient } from "../src/resourceManagementClient";
|
|
4
|
+
import { createHttpHeaders } from "@azure/core-rest-pipeline";
|
|
5
|
+
describe("Mock test for CAE with ResourceManagementClient", () => {
|
|
6
|
+
// this is not a real token, does not contain any sensitive info, just for test.
|
|
7
|
+
// You could refer the check in core https://github.com/azure/azure-sdk-for-js/blob/57056dcef4d646fdca6f4af7bd5b2539c3cb57a2/sdk/core/core-rest-pipeline/src/policies/bearerTokenAuthenticationPolicy.ts#L375 to verify if your CAE challenge header is valid or not.
|
|
8
|
+
const caeChallenge = `Bearer realm="", error_description="Continuous access evaluation resulted in challenge", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTcyNjI1ODEyMiJ9fX0=" `;
|
|
9
|
+
// This header is invalid because the claims is empty
|
|
10
|
+
const invalidCAEChallenge = `Bearer realm="", error_description="", error="insufficient_claims", claims=""`;
|
|
11
|
+
it("should proceed CAE process for mgmt client if a valid CAE challenge", function () {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
var _a, e_1, _b, _c;
|
|
14
|
+
let getTokenCount = 0;
|
|
15
|
+
const credential = {
|
|
16
|
+
getToken: (scopes) => __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
getTokenCount++;
|
|
18
|
+
let token = "testToken";
|
|
19
|
+
if (getTokenCount === 0) {
|
|
20
|
+
token = "firstToken";
|
|
21
|
+
}
|
|
22
|
+
return { token: "testToken", expiresOnTimestamp: 11111 };
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
let getRequestCount = 0;
|
|
26
|
+
let request;
|
|
27
|
+
const client = new ResourceManagementClient(credential, "subscriptionID", {
|
|
28
|
+
httpClient: {
|
|
29
|
+
sendRequest: (req) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
request = req;
|
|
31
|
+
getRequestCount++;
|
|
32
|
+
if (getRequestCount === 1) {
|
|
33
|
+
return { request: req, status: 401, headers: createHttpHeaders({ "www-authenticate": caeChallenge }) };
|
|
34
|
+
}
|
|
35
|
+
return { request: req, status: 200, headers: createHttpHeaders() };
|
|
36
|
+
}),
|
|
37
|
+
},
|
|
38
|
+
credential
|
|
39
|
+
});
|
|
40
|
+
const result = yield client.operations.list();
|
|
41
|
+
const items = [];
|
|
42
|
+
try {
|
|
43
|
+
for (var _d = true, result_1 = __asyncValues(result), result_1_1; result_1_1 = yield result_1.next(), _a = result_1_1.done, !_a; _d = true) {
|
|
44
|
+
_c = result_1_1.value;
|
|
45
|
+
_d = false;
|
|
46
|
+
let item = _c;
|
|
47
|
+
items.push(item);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
51
|
+
finally {
|
|
52
|
+
try {
|
|
53
|
+
if (!_d && !_a && (_b = result_1.return)) yield _b.call(result_1);
|
|
54
|
+
}
|
|
55
|
+
finally { if (e_1) throw e_1.error; }
|
|
56
|
+
}
|
|
57
|
+
assert.equal(items.length, 0);
|
|
58
|
+
assert.equal(getRequestCount, 2);
|
|
59
|
+
assert.equal(getTokenCount, 2);
|
|
60
|
+
assert.deepEqual(request.headers.get("authorization"), "Bearer testToken");
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
it("should not proceed CAE process for mgmt client if an invalid CAE challenge", function () {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var _a, e_2, _b, _c;
|
|
66
|
+
let getTokenCount = 0;
|
|
67
|
+
const credential = {
|
|
68
|
+
getToken: (scopes) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
getTokenCount++;
|
|
70
|
+
let token = "testToken";
|
|
71
|
+
if (getTokenCount === 0) {
|
|
72
|
+
token = "firstToken";
|
|
73
|
+
}
|
|
74
|
+
return { token: "testToken", expiresOnTimestamp: 11111 };
|
|
75
|
+
}),
|
|
76
|
+
};
|
|
77
|
+
let getRequestCount = 0;
|
|
78
|
+
let request;
|
|
79
|
+
const client = new ResourceManagementClient(credential, "subscriptionID", {
|
|
80
|
+
httpClient: {
|
|
81
|
+
sendRequest: (req) => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
request = req;
|
|
83
|
+
getRequestCount++;
|
|
84
|
+
if (getRequestCount === 1) {
|
|
85
|
+
return { request: req, status: 401, headers: createHttpHeaders({ "www-authenticate": invalidCAEChallenge }) };
|
|
86
|
+
}
|
|
87
|
+
return { request: req, status: 200, headers: createHttpHeaders() };
|
|
88
|
+
}),
|
|
89
|
+
},
|
|
90
|
+
credential
|
|
91
|
+
});
|
|
92
|
+
try {
|
|
93
|
+
const result = yield client.operations.list();
|
|
94
|
+
const items = [];
|
|
95
|
+
try {
|
|
96
|
+
for (var _d = true, result_2 = __asyncValues(result), result_2_1; result_2_1 = yield result_2.next(), _a = result_2_1.done, !_a; _d = true) {
|
|
97
|
+
_c = result_2_1.value;
|
|
98
|
+
_d = false;
|
|
99
|
+
let item = _c;
|
|
100
|
+
items.push(item);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
104
|
+
finally {
|
|
105
|
+
try {
|
|
106
|
+
if (!_d && !_a && (_b = result_2.return)) yield _b.call(result_2);
|
|
107
|
+
}
|
|
108
|
+
finally { if (e_2) throw e_2.error; }
|
|
109
|
+
}
|
|
110
|
+
assert.fail("Should not reach here and throw 401 exception");
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
assert.equal(e.statusCode, 401);
|
|
114
|
+
assert.equal(getRequestCount, 1);
|
|
115
|
+
assert.equal(getTokenCount, 1);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
//# sourceMappingURL=cae_mock_test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cae_mock_test.js","sourceRoot":"","sources":["../../test/cae_mock_test.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,QAAQ,CAAC,iDAAiD,EAAE,GAAG,EAAE;IAC/D,gFAAgF;IAChF,qQAAqQ;IACrQ,MAAM,YAAY,GAAG,0NAA0N,CAAC;IAChP,qDAAqD;IACrD,MAAM,mBAAmB,GAAG,+EAA+E,CAAC;IAC5G,EAAE,CAAC,qEAAqE,EAAE;;;YACxE,IAAI,aAAa,GAAG,CAAC,CAAC;YACtB,MAAM,UAAU,GAAoB;gBAClC,QAAQ,EAAE,CAAO,MAAM,EAAE,EAAE;oBACzB,aAAa,EAAE,CAAC;oBAChB,IAAI,KAAK,GAAG,WAAW,CAAC;oBACxB,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;wBACxB,KAAK,GAAG,YAAY,CAAC;oBACvB,CAAC;oBACD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC;gBAC3D,CAAC,CAAA;aACF,CAAC;YAEF,IAAI,eAAe,GAAG,CAAC,CAAC;YACxB,IAAI,OAAyB,CAAC;YAC9B,MAAM,MAAM,GAAG,IAAI,wBAAwB,CAAC,UAAU,EAAE,gBAAgB,EAAE;gBACxE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IAAI,CAAC,+CAA+C,CAAC,CAAC;YAC/D,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;gBAChC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;gBACjC,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;YACjC,CAAC;QACH,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"sdk-type": "mgmt",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "A generated SDK for ResourceManagementClient.",
|
|
6
|
-
"version": "5.2.1-alpha.
|
|
6
|
+
"version": "5.2.1-alpha.20250114.1",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=18.0.0"
|
|
9
9
|
},
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@azure/core-client": "^1.7.0",
|
|
14
14
|
"@azure/core-lro": "^2.5.0",
|
|
15
15
|
"@azure/core-paging": "^1.2.0",
|
|
16
|
-
"@azure/core-rest-pipeline": "^1.
|
|
16
|
+
"@azure/core-rest-pipeline": "^1.18.2",
|
|
17
17
|
"tslib": "^2.2.0"
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|