@nsshunt/stsappframework 3.1.217 → 3.1.218

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsshunt/stsappframework",
3
- "version": "3.1.217",
3
+ "version": "3.1.218",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -29,6 +29,7 @@
29
29
  "@babel/preset-typescript": "^7.25.7",
30
30
  "@eslint/eslintrc": "^3.1.0",
31
31
  "@eslint/js": "^9.13.0",
32
+ "@nsshunt/stsdevtools": "^1.0.33",
32
33
  "@tsconfig/node20": "^20.1.4",
33
34
  "@types/cookie-parser": "^1.4.7",
34
35
  "@types/debug": "^4.1.12",
@@ -1,283 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.TestHelper = void 0;
30
- /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
31
- const chalk_1 = __importDefault(require("chalk"));
32
- const tough = __importStar(require("tough-cookie"));
33
- const https_1 = __importDefault(require("https"));
34
- const crypto_1 = __importDefault(require("crypto"));
35
- const axios_1 = __importDefault(require("axios"));
36
- const testcontainers_1 = require("testcontainers");
37
- const stsconfig_1 = require("@nsshunt/stsconfig");
38
- const stsutils_1 = require("@nsshunt/stsutils");
39
- const stsauthclient_1 = require("@nsshunt/stsauthclient");
40
- class TestHelper {
41
- //#regexBase64URL = /^[A-Za-z0-9_-]+$/ // Base64URL - https://base64.guru/standards/base64url
42
- #regexURLSafeStringComponent = /[-a-zA-Z0-9@:%._+~#=]{1,256}/; // URL safe string component
43
- //#regexBase64 = /(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/ // Base64 - https://stackoverflow.com/questions/475074/regex-to-parse-or-validate-base64-data
44
- #regexSTSBase64 = /SES_(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/; // Base64
45
- #regexJWT = /[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+/; // JWT (Base64URL.Base64URL.Base64URL)
46
- #authUtilsNode = new stsauthclient_1.AuthUtilsNode(stsutils_1.defaultLogger);
47
- #databaseContainer;
48
- #stsAuthContainer;
49
- #network;
50
- #authEndpoint = '';
51
- #authPort = '';
52
- #authHost = '';
53
- #httpsAgent = null;
54
- constructor() {
55
- this.#authEndpoint = 'https://localhost:3002'; //@@
56
- }
57
- LogDebugMessage(message) {
58
- stsutils_1.defaultLogger.debug(message);
59
- }
60
- #GetHttpsAgent = () => {
61
- if (this.#httpsAgent === null) {
62
- // https://nodejs.org/api/http.html#class-httpagent
63
- this.#httpsAgent = new https_1.default.Agent({
64
- keepAlive: stsconfig_1.goptions.keepAlive,
65
- maxSockets: stsconfig_1.goptions.maxSockets,
66
- maxTotalSockets: stsconfig_1.goptions.maxTotalSockets,
67
- maxFreeSockets: stsconfig_1.goptions.maxFreeSockets,
68
- timeout: stsconfig_1.goptions.timeout,
69
- rejectUnauthorized: false
70
- });
71
- }
72
- return this.#httpsAgent;
73
- };
74
- StartNetwork = async () => {
75
- this.#network = await new testcontainers_1.Network().start();
76
- };
77
- StopNetwork = async () => {
78
- await this.#network.stop();
79
- };
80
- get network() {
81
- return this.#network;
82
- }
83
- get authPort() {
84
- return this.#authPort;
85
- }
86
- get authHost() {
87
- return this.#authHost;
88
- }
89
- get authEndpoint() {
90
- return this.#authEndpoint;
91
- }
92
- get getHttpsAgent() {
93
- return this.#GetHttpsAgent();
94
- }
95
- CreateRandomString = () => {
96
- const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.'; // /[0-9A-Za-z\-_~.]/
97
- let random = '';
98
- const randomValues = Array.from(crypto_1.default.getRandomValues(new Uint8Array(43)));
99
- randomValues.forEach(v => (random += charset[v % charset.length]));
100
- return random;
101
- };
102
- Login = async (username, password) => {
103
- const client_id = process.env.CLIENT_ID;
104
- const nonce = crypto_1.default.randomBytes(43).toString('base64'); //CreateRandomString();
105
- const response_type = 'code';
106
- const redirect_uri = process.env.REDIRECT_URI;
107
- const response_mode = 'query';
108
- const scope = process.env.SCOPE;
109
- const state = crypto_1.default.randomBytes(43).toString('base64'); // CreateRandomString();
110
- const code_verifier = this.CreateRandomString();
111
- const code_challenge = crypto_1.default.createHash('sha256').update(code_verifier).digest('base64');
112
- const code_challenge_method = 'S256';
113
- const authoriseOptions = {
114
- email: username,
115
- password,
116
- client_id,
117
- nonce,
118
- response_type,
119
- redirect_uri,
120
- response_mode,
121
- scope,
122
- state,
123
- code_challenge,
124
- code_challenge_method
125
- };
126
- const url = `${this.#authEndpoint}${stsconfig_1.goptions.asapiroot}/login`;
127
- const headers = { 'Content-Type': 'application/json' };
128
- const retVal = await (0, axios_1.default)({
129
- url,
130
- method: 'post',
131
- data: authoriseOptions,
132
- headers: headers,
133
- httpsAgent: this.#GetHttpsAgent()
134
- });
135
- //const cookieString = retVal.headers['set-cookie'];
136
- /*
137
- const api = request(this.#endpoint);
138
- const retVal: any = await (api as any)
139
- .post(`${goptions.asapiroot}/login`)
140
- .send(authoriseOptions)
141
- //.expect('set-cookie', /consent_cookie=.*; Max-Age=86; Path=\/; Expires=.*; HttpOnly; Secure; SameSite=Strict/);
142
-
143
- const cookieString = retVal.header['set-cookie'];
144
-
145
- if (cookieString) {
146
- retVal.cookie = new Cookie(cookieString[0]);
147
- }
148
- */
149
- return retVal;
150
- };
151
- /*
152
- GetAuthServerAPITokenFromServer = async (): Promise<string> => {
153
- return await this.#authUtilsNode.GetAPITokenFromAuthServer(STSClientID.STSTestingService,
154
- "eN9u0mHZLGWZrdnE1zit2vL6xwUFW466sTZcbkXDml5KWxlvKaZ1uiOZmA==",
155
- goptions.asapiidentifier, this.#authEndpoint)
156
- }
157
- */
158
- ValidateJWT = async (token) => {
159
- return await this.#authUtilsNode.ValidateJWT(token, stsconfig_1.goptions.asapiidentifier, this.#authEndpoint);
160
- };
161
- StartDatabase = async () => {
162
- this.#databaseContainer = await new testcontainers_1.GenericContainer("postgres")
163
- .withExposedPorts(5432)
164
- .withEnvironment({
165
- POSTGRES_PASSWORD: "postgres",
166
- //UV_THREADPOOL_SIZE: "64"
167
- })
168
- .withNetwork(this.#network)
169
- .withNetworkAliases("database")
170
- .start();
171
- const httpPort = this.#databaseContainer.getMappedPort(5432);
172
- const host = this.#databaseContainer.getHost();
173
- const networkIpAddress = this.#databaseContainer.getIpAddress(this.#network.getName());
174
- process.env.DB_HOST = `${host}:${httpPort}`;
175
- (0, stsconfig_1.$ResetOptions)();
176
- this.LogDebugMessage(chalk_1.default.green(`httpPort: [${httpPort}]`));
177
- this.LogDebugMessage(chalk_1.default.green(`host: [${host}]`));
178
- this.LogDebugMessage(chalk_1.default.green(`networkIpAddress: [${networkIpAddress}]`));
179
- this.LogDebugMessage(chalk_1.default.green(`connectionString: [${stsconfig_1.goptions.connectionString}]`));
180
- this.LogDebugMessage(chalk_1.default.green(`defaultDatabaseConnectionString: [${stsconfig_1.goptions.defaultDatabaseConnectionString}]`));
181
- };
182
- StopDatabase = async () => {
183
- if (this.#databaseContainer) {
184
- await this.#databaseContainer.stop();
185
- this.LogDebugMessage(chalk_1.default.yellow(`Used the following parameters for the database during testing:`));
186
- this.LogDebugMessage(chalk_1.default.yellow(`connectionString: [${stsconfig_1.goptions.connectionString}]`));
187
- this.LogDebugMessage(chalk_1.default.yellow(`defaultDatabaseConnectionString: [${stsconfig_1.goptions.defaultDatabaseConnectionString}]`));
188
- }
189
- };
190
- // Note: .withCopyFilesToContainer and .withCopyContentToContainer have a defect in that Jest will not close. A file handle/stream is left open
191
- // within the underlying code.
192
- InitializeDatabase = async () => {
193
- const stsAuthContainerInit = await new testcontainers_1.GenericContainer("serza/stsauth:latest")
194
- .withEnvironment({
195
- DB_USER: "postgres",
196
- DB_PASSWORD: "postgres",
197
- DB_HOST: "database:5432", // "192.168.14.101",
198
- POOL_SIZE: "50",
199
- MAX_CPU: "2",
200
- DEBUG: "proc*",
201
- HTTPS_SERVER_KEY_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.key",
202
- HTTPS_SERVER_CERT_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.cert",
203
- AS_ENDPOINT: "https://stscore.stsmda.org"
204
- })
205
- .withCommand(["node", "dist/app", "create"])
206
- .withNetwork(this.#network)
207
- .withNetworkAliases("stsauthrunnerinit")
208
- .withWaitStrategy(testcontainers_1.Wait.forLogMessage(`User registered: {"status":200,"detail":{"id":"USR_STSGlobalAdminUser@stsmda.com","name":"STSGlobalAdminUser@stsmda.com","email":"STSGlobalAdminUser@stsmda.com","roles":[]}}`))
209
- .start();
210
- await (0, stsutils_1.Sleep)(500);
211
- await stsAuthContainerInit.stop();
212
- };
213
- StartAuthService = async () => {
214
- this.#stsAuthContainer = await new testcontainers_1.GenericContainer("serza/stsauth:latest")
215
- .withExposedPorts(3002)
216
- .withEnvironment({
217
- DB_USER: "postgres",
218
- DB_PASSWORD: "postgres",
219
- DB_HOST: "database:5432",
220
- POOL_SIZE: "50",
221
- MAX_CPU: "2",
222
- DEBUG: "proc*",
223
- HTTPS_SERVER_KEY_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.key",
224
- HTTPS_SERVER_CERT_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.cert",
225
- AS_ENDPOINT: "https://stscore.stsmda.org"
226
- })
227
- .withNetwork(this.#network)
228
- .withNetworkAliases("stsauthrunner")
229
- .withWaitStrategy(testcontainers_1.Wait.forHttp("/stsauth/v1.0/latency", 3002).usingTls().allowInsecure())
230
- .start();
231
- const httpAuthPort = this.#stsAuthContainer.getMappedPort(3002);
232
- await (0, stsutils_1.Sleep)(200);
233
- this.LogDebugMessage(chalk_1.default.green(`-------------------------------------------------------------------------------------------`));
234
- this.LogDebugMessage(chalk_1.default.green(` *** STSAuth Started ***: [${httpAuthPort}]`));
235
- this.LogDebugMessage(chalk_1.default.green(`-------------------------------------------------------------------------------------------`));
236
- this.#authHost = 'https://localhost';
237
- this.#authPort = httpAuthPort;
238
- this.#authEndpoint = `${this.#authHost}:${this.#authPort}`;
239
- };
240
- StopAuthService = async () => {
241
- if (this.#stsAuthContainer) {
242
- await this.#stsAuthContainer.stop();
243
- await (0, stsutils_1.Sleep)(200);
244
- }
245
- };
246
- TestLoginAndVerify = async () => {
247
- expect.assertions(4);
248
- const retVal = await this.Login('user01@stsmda.com.au', 'user01password');
249
- expect(retVal.status).toEqual(200);
250
- this.LogDebugMessage(chalk_1.default.red(`${JSON.stringify(retVal.data)}`));
251
- this.LogDebugMessage(chalk_1.default.magenta(`${JSON.stringify(retVal.headers)}`));
252
- this.LogDebugMessage(chalk_1.default.yellow(`${JSON.stringify(retVal.headers['set-cookie'])}`));
253
- const cookies = retVal.headers['set-cookie'];
254
- this.LogDebugMessage(chalk_1.default.yellow(`${cookies[0]}`));
255
- this.LogDebugMessage(chalk_1.default.green(`${JSON.stringify(tough.Cookie.parse(cookies[0]))}`));
256
- const cookie = tough.Cookie.parse(cookies[0]);
257
- const desiredCookieResultAxios = {
258
- key: 'consent_cookie',
259
- value: expect.stringMatching(this.#regexURLSafeStringComponent),
260
- path: '/',
261
- secure: true,
262
- httpOnly: true,
263
- sameSite: 'strict',
264
- };
265
- const cookieResult = JSON.parse(JSON.stringify(cookie));
266
- expect(cookieResult).toMatchObject(desiredCookieResultAxios);
267
- const cookieExpireDate = new Date(cookie.expires);
268
- expect(cookieExpireDate.getTime()).toBeGreaterThan(new Date().getTime());
269
- const desiredResult = {
270
- sessionId: expect.stringMatching(this.#regexSTSBase64),
271
- id_token: expect.stringMatching(this.#regexJWT),
272
- consentRequired: [
273
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.create',
274
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.read',
275
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.update',
276
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.delete'
277
- ]
278
- };
279
- expect(retVal.data.detail).toMatchObject(desiredResult);
280
- };
281
- }
282
- exports.TestHelper = TestHelper;
283
- //# sourceMappingURL=testHelpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testHelpers.js","sourceRoot":"","sources":["../src/testHelpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAkD,CAAE,UAAU;AAC9D,kDAAyB;AAEzB,oDAAqC;AAErC,kDAAyB;AACzB,oDAA2B;AAE3B,kDAAyB;AAEzB,mDAAgE;AAEhE,kDAA4D;AAE5D,gDAAwD;AAExD,0DAAsD;AAEtD,MAAa,UAAU;IACnB,8FAA8F;IAC9F,4BAA4B,GAAG,8BAA8B,CAAA,CAAC,4BAA4B;IAC1F,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AAc,CAAC,IAAI,CAAC,4BAA4B,CAAC;YAC/D,IAAI,EAAE,GAAG;YACT,MAAM,EAAE,IAAI;YACZ,QAAQ,EAAE,IAAI;YACd,QAAQ,EAAE,QAAQ;SACrB,CAAA;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACxD,MAAM,CAAC,YAAY,CAAC,CAAC,aAAa,CAAC,wBAAwB,CAAC,CAAC;QAE7D,MAAM,gBAAgB,GAAG,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAClD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,eAAe,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAEzE,MAAM,aAAa,GAAG;YAClB,SAAS,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,eAAe,CAAC;YACtD,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC;YAC/C,eAAe,EAAE;gBACb,yDAAyD;gBACzD,uDAAuD;gBACvD,yDAAyD;gBACzD,yDAAyD;aAC5D;SACJ,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;IAC5D,CAAC,CAAA;CAqBJ;AApTD,gCAoTC"}
@@ -1,327 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
- import chalk from 'chalk'
3
-
4
- import * as tough from 'tough-cookie'
5
-
6
- import https from 'https'
7
- import crypto from 'crypto'
8
-
9
- import axios from 'axios'
10
-
11
- import { GenericContainer, Network, Wait } from "testcontainers"
12
-
13
- import { goptions, $ResetOptions } from '@nsshunt/stsconfig'
14
-
15
- import { Sleep, defaultLogger } from '@nsshunt/stsutils'
16
-
17
- import { AuthUtilsNode } from '@nsshunt/stsauthclient'
18
-
19
- export class TestHelper {
20
- //#regexBase64URL = /^[A-Za-z0-9_-]+$/ // Base64URL - https://base64.guru/standards/base64url
21
- #regexURLSafeStringComponent = /[-a-zA-Z0-9@:%._+~#=]{1,256}/ // URL safe string component
22
- //#regexBase64 = /(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/ // Base64 - https://stackoverflow.com/questions/475074/regex-to-parse-or-validate-base64-data
23
- #regexSTSBase64 = /SES_(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?/ // Base64
24
- #regexJWT = /[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+/ // JWT (Base64URL.Base64URL.Base64URL)
25
-
26
- #authUtilsNode = new AuthUtilsNode(defaultLogger);
27
-
28
- #databaseContainer: any;
29
- #stsAuthContainer: any;
30
- #network: any;
31
- #authEndpoint = '';
32
- #authPort = '';
33
- #authHost = '';
34
- #httpsAgent: https.Agent | null = null;
35
-
36
- constructor() {
37
- this.#authEndpoint = 'https://localhost:3002'; //@@
38
- }
39
-
40
- LogDebugMessage(message: any) {
41
- defaultLogger.debug(message);
42
- }
43
-
44
- #GetHttpsAgent = () =>
45
- {
46
- if (this.#httpsAgent === null) {
47
- // https://nodejs.org/api/http.html#class-httpagent
48
- this.#httpsAgent = new https.Agent({
49
- keepAlive: goptions.keepAlive,
50
- maxSockets: goptions.maxSockets,
51
- maxTotalSockets: goptions.maxTotalSockets,
52
- maxFreeSockets: goptions.maxFreeSockets,
53
- timeout: goptions.timeout,
54
- rejectUnauthorized: false
55
- });
56
- }
57
- return this.#httpsAgent;
58
- }
59
-
60
- StartNetwork = async () => {
61
- this.#network = await new Network().start();
62
- }
63
-
64
- StopNetwork = async () => {
65
- await this.#network.stop();
66
- }
67
-
68
- get network() {
69
- return this.#network;
70
- }
71
-
72
- get authPort() {
73
- return this.#authPort;
74
- }
75
-
76
- get authHost() {
77
- return this.#authHost;
78
- }
79
-
80
- get authEndpoint() {
81
- return this.#authEndpoint;
82
- }
83
-
84
- get getHttpsAgent() {
85
- return this.#GetHttpsAgent();
86
- }
87
-
88
- CreateRandomString = () => {
89
- const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.'; // /[0-9A-Za-z\-_~.]/
90
- let random = '';
91
- const randomValues: number[] = Array.from(crypto.getRandomValues(new Uint8Array(43)));
92
- randomValues.forEach(v => (random += charset[v % charset.length]));
93
- return random;
94
- }
95
-
96
- Login = async (username: string, password: string) => {
97
- const client_id = process.env.CLIENT_ID as string;
98
- const nonce = crypto.randomBytes(43).toString('base64'); //CreateRandomString();
99
- const response_type = 'code';
100
- const redirect_uri = process.env.REDIRECT_URI as string;
101
- const response_mode = 'query';
102
- const scope = process.env.SCOPE as string;
103
- const state = crypto.randomBytes(43).toString('base64'); // CreateRandomString();
104
- const code_verifier = this.CreateRandomString();
105
- const code_challenge = crypto.createHash('sha256').update(code_verifier).digest('base64');
106
- const code_challenge_method = 'S256';
107
-
108
- const authoriseOptions: any = {
109
- email: username,
110
- password,
111
- client_id,
112
- nonce,
113
- response_type,
114
- redirect_uri,
115
- response_mode,
116
- scope,
117
- state,
118
- code_challenge,
119
- code_challenge_method
120
- }
121
-
122
- const url = `${this.#authEndpoint}${goptions.asapiroot}/login`;
123
- const headers = { 'Content-Type': 'application/json'};
124
-
125
- const retVal = await axios({
126
- url
127
- ,method: 'post'
128
- ,data: authoriseOptions
129
- ,headers: headers
130
- ,httpsAgent: this.#GetHttpsAgent()
131
- });
132
-
133
- //const cookieString = retVal.headers['set-cookie'];
134
-
135
- /*
136
- const api = request(this.#endpoint);
137
- const retVal: any = await (api as any)
138
- .post(`${goptions.asapiroot}/login`)
139
- .send(authoriseOptions)
140
- //.expect('set-cookie', /consent_cookie=.*; Max-Age=86; Path=\/; Expires=.*; HttpOnly; Secure; SameSite=Strict/);
141
-
142
- const cookieString = retVal.header['set-cookie'];
143
-
144
- if (cookieString) {
145
- retVal.cookie = new Cookie(cookieString[0]);
146
- }
147
- */
148
-
149
- return retVal;
150
- }
151
-
152
- /*
153
- GetAuthServerAPITokenFromServer = async (): Promise<string> => {
154
- return await this.#authUtilsNode.GetAPITokenFromAuthServer(STSClientID.STSTestingService,
155
- "eN9u0mHZLGWZrdnE1zit2vL6xwUFW466sTZcbkXDml5KWxlvKaZ1uiOZmA==",
156
- goptions.asapiidentifier, this.#authEndpoint)
157
- }
158
- */
159
-
160
- ValidateJWT = async (token: string): Promise<string> => {
161
- return await this.#authUtilsNode.ValidateJWT(token, goptions.asapiidentifier, this.#authEndpoint);
162
- }
163
-
164
- StartDatabase = async () => {
165
- this.#databaseContainer = await new GenericContainer("postgres")
166
- .withExposedPorts(5432)
167
- .withEnvironment({
168
- POSTGRES_PASSWORD: "postgres",
169
- //UV_THREADPOOL_SIZE: "64"
170
- })
171
- .withNetwork(this.#network)
172
- .withNetworkAliases("database")
173
- .start();
174
-
175
- const httpPort = this.#databaseContainer.getMappedPort(5432);
176
- const host = this.#databaseContainer.getHost();
177
- const networkIpAddress = this.#databaseContainer.getIpAddress(this.#network.getName());
178
-
179
- process.env.DB_HOST = `${host}:${httpPort}`;
180
-
181
- $ResetOptions();
182
-
183
- this.LogDebugMessage(chalk.green(`httpPort: [${httpPort}]`));
184
- this.LogDebugMessage(chalk.green(`host: [${host}]`));
185
- this.LogDebugMessage(chalk.green(`networkIpAddress: [${networkIpAddress}]`));
186
- this.LogDebugMessage(chalk.green(`connectionString: [${goptions.connectionString}]`));
187
- this.LogDebugMessage(chalk.green(`defaultDatabaseConnectionString: [${goptions.defaultDatabaseConnectionString }]`));
188
- }
189
-
190
- StopDatabase = async () => {
191
- if (this.#databaseContainer) {
192
- await this.#databaseContainer.stop();
193
-
194
- this.LogDebugMessage(chalk.yellow(`Used the following parameters for the database during testing:`));
195
- this.LogDebugMessage(chalk.yellow(`connectionString: [${goptions.connectionString}]`));
196
- this.LogDebugMessage(chalk.yellow(`defaultDatabaseConnectionString: [${goptions.defaultDatabaseConnectionString }]`));
197
- }
198
- }
199
-
200
- // Note: .withCopyFilesToContainer and .withCopyContentToContainer have a defect in that Jest will not close. A file handle/stream is left open
201
- // within the underlying code.
202
- InitializeDatabase = async () => {
203
- const stsAuthContainerInit = await new GenericContainer("serza/stsauth:latest")
204
- .withEnvironment({
205
- DB_USER: "postgres",
206
- DB_PASSWORD: "postgres",
207
- DB_HOST: "database:5432", // "192.168.14.101",
208
- POOL_SIZE: "50",
209
- MAX_CPU: "2",
210
- DEBUG: "proc*",
211
- HTTPS_SERVER_KEY_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.key",
212
- HTTPS_SERVER_CERT_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.cert",
213
- AS_ENDPOINT: "https://stscore.stsmda.org"
214
- })
215
- .withCommand(["node", "dist/app", "create"])
216
- .withNetwork(this.#network)
217
- .withNetworkAliases("stsauthrunnerinit")
218
- .withWaitStrategy(Wait.forLogMessage(`User registered: {"status":200,"detail":{"id":"USR_STSGlobalAdminUser@stsmda.com","name":"STSGlobalAdminUser@stsmda.com","email":"STSGlobalAdminUser@stsmda.com","roles":[]}}`))
219
- .start();
220
-
221
- await Sleep(500);
222
-
223
- await stsAuthContainerInit.stop();
224
- }
225
-
226
- StartAuthService = async () => {
227
- this.#stsAuthContainer = await new GenericContainer("serza/stsauth:latest")
228
- .withExposedPorts(3002)
229
- .withEnvironment({
230
- DB_USER: "postgres",
231
- DB_PASSWORD: "postgres",
232
- DB_HOST: "database:5432",
233
- POOL_SIZE: "50",
234
- MAX_CPU: "2",
235
- DEBUG: "proc*",
236
- HTTPS_SERVER_KEY_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.key",
237
- HTTPS_SERVER_CERT_PATH: "/var/lib/sts/stsglobalresources/keys-tmp/server.cert",
238
- AS_ENDPOINT: "https://stscore.stsmda.org"
239
- })
240
- .withNetwork(this.#network)
241
- .withNetworkAliases("stsauthrunner")
242
- .withWaitStrategy(Wait.forHttp("/stsauth/v1.0/latency", 3002).usingTls().allowInsecure())
243
- .start();
244
-
245
- const httpAuthPort = this.#stsAuthContainer.getMappedPort(3002);
246
-
247
- await Sleep(200);
248
- this.LogDebugMessage(chalk.green(`-------------------------------------------------------------------------------------------`));
249
- this.LogDebugMessage(chalk.green(` *** STSAuth Started ***: [${httpAuthPort}]`));
250
- this.LogDebugMessage(chalk.green(`-------------------------------------------------------------------------------------------`));
251
-
252
- this.#authHost = 'https://localhost'
253
- this.#authPort = httpAuthPort;
254
- this.#authEndpoint = `${this.#authHost}:${this.#authPort}`;
255
- }
256
-
257
- StopAuthService = async () => {
258
- if (this.#stsAuthContainer) {
259
- await this.#stsAuthContainer.stop();
260
- await Sleep(200);
261
- }
262
- }
263
-
264
- TestLoginAndVerify = async () => {
265
- expect.assertions(4);
266
-
267
- const retVal = await this.Login('user01@stsmda.com.au', 'user01password');
268
- expect(retVal.status).toEqual(200);
269
-
270
- this.LogDebugMessage(chalk.red(`${JSON.stringify(retVal.data)}`));
271
- this.LogDebugMessage(chalk.magenta(`${JSON.stringify(retVal.headers)}`));
272
- this.LogDebugMessage(chalk.yellow(`${JSON.stringify(retVal.headers['set-cookie'])}`));
273
-
274
- const cookies = retVal.headers['set-cookie'] as string[];
275
- this.LogDebugMessage(chalk.yellow(`${cookies[0]}`));
276
- this.LogDebugMessage(chalk.green(`${JSON.stringify(tough.Cookie.parse(cookies[0]))}`));
277
-
278
- const cookie = tough.Cookie.parse(cookies[0]) as tough.Cookie;
279
-
280
- const desiredCookieResultAxios = {
281
- key: 'consent_cookie',
282
- value: expect.stringMatching(this.#regexURLSafeStringComponent),
283
- path: '/',
284
- secure: true,
285
- httpOnly: true,
286
- sameSite: 'strict',
287
- }
288
-
289
- const cookieResult = JSON.parse(JSON.stringify(cookie));
290
- expect(cookieResult).toMatchObject(desiredCookieResultAxios);
291
-
292
- const cookieExpireDate = new Date(cookie.expires);
293
- expect(cookieExpireDate.getTime()).toBeGreaterThan(new Date().getTime());
294
-
295
- const desiredResult = {
296
- sessionId: expect.stringMatching(this.#regexSTSBase64),
297
- id_token: expect.stringMatching(this.#regexJWT),
298
- consentRequired: [
299
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.create',
300
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.read',
301
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.update',
302
- 'api://d8277fce-bb48-44c2-bbf1-257fe13a444b/res01.delete'
303
- ]
304
- }
305
- expect(retVal.data.detail).toMatchObject(desiredResult);
306
- }
307
-
308
- /*
309
- TestValidateJWT = async () => {
310
- expect.assertions(1);
311
-
312
- const access_token = await this.GetAuthServerAPITokenFromServer();
313
- this.LogDebugMessage(chalk.green(`access_token: [${access_token}]`));
314
-
315
- const retVal = await this.ValidateJWT(access_token);
316
- // https://jestjs.io/docs/expect#tomatchobjectobject
317
- const desiredJWT = {
318
- scope: 'offline_access session.read session.update',
319
- iss: 'https://stscore.stsmda.org/oauth2/v2.0',
320
- aud: 'https://stsmda.com.au/stsauthapi/v1.0/',
321
- sub: 'session'
322
- };
323
-
324
- expect(retVal).toMatchObject(desiredJWT);
325
- }
326
- */
327
- }
@@ -1,23 +0,0 @@
1
- import https from 'https';
2
- export declare class TestHelper {
3
- #private;
4
- constructor();
5
- LogDebugMessage(message: any): void;
6
- StartNetwork: () => Promise<void>;
7
- StopNetwork: () => Promise<void>;
8
- get network(): any;
9
- get authPort(): string;
10
- get authHost(): string;
11
- get authEndpoint(): string;
12
- get getHttpsAgent(): https.Agent;
13
- CreateRandomString: () => string;
14
- Login: (username: string, password: string) => Promise<import("axios").AxiosResponse<any, any>>;
15
- ValidateJWT: (token: string) => Promise<string>;
16
- StartDatabase: () => Promise<void>;
17
- StopDatabase: () => Promise<void>;
18
- InitializeDatabase: () => Promise<void>;
19
- StartAuthService: () => Promise<void>;
20
- StopAuthService: () => Promise<void>;
21
- TestLoginAndVerify: () => Promise<void>;
22
- }
23
- //# sourceMappingURL=testHelpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"testHelpers.d.ts","sourceRoot":"","sources":["../src/testHelpers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,MAAM,OAAO,CAAA;AAazB,qBAAa,UAAU;;;IAqBnB,eAAe,CAAC,OAAO,EAAE,GAAG;IAoB5B,YAAY,sBAEX;IAED,WAAW,sBAEV;IAED,IAAI,OAAO,QAEV;IAED,IAAI,QAAQ,WAEX;IAED,IAAI,QAAQ,WAEX;IAED,IAAI,YAAY,WAEf;IAED,IAAI,aAAa,gBAEhB;IAED,kBAAkB,eAMjB;IAED,KAAK,aAAoB,MAAM,YAAY,MAAM,sDAsDhD;IAUD,WAAW,UAAiB,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAEnD;IAED,aAAa,sBAwBZ;IAED,YAAY,sBAQX;IAID,kBAAkB,sBAsBjB;IAED,gBAAgB,sBA6Bf;IAED,eAAe,sBAKd;IAED,kBAAkB,sBA0CjB;CAqBJ"}