@nsshunt/stsappframework 3.1.216 → 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/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/src/index.ts +0 -2
- package/types/index.d.ts +0 -1
- package/types/index.d.ts.map +1 -1
- package/dist/authutilsnode.js +0 -310
- package/dist/authutilsnode.js.map +0 -1
- package/dist/testHelpers.js +0 -283
- package/dist/testHelpers.js.map +0 -1
- package/src/authutilsnode.ts +0 -360
- package/src/socketIoServerHelper.ts_bak +0 -165
- package/src/testHelpers.ts +0 -327
- package/types/authutilsnode.d.ts +0 -27
- package/types/authutilsnode.d.ts.map +0 -1
- package/types/testHelpers.d.ts +0 -23
- package/types/testHelpers.d.ts.map +0 -1
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
2
|
-
import { JSONObject, ISTSLogger } from '@nsshunt/stsutils'
|
|
3
|
-
|
|
4
|
-
import { Server, Namespace, Socket } from "socket.io";
|
|
5
|
-
|
|
6
|
-
import { STSSocketIONamespace, STSServerSocket, STSNamespace,
|
|
7
|
-
ISocketIoServerHelper, ServerEventCb, InterServerEvents, STSSocketIONamespaces } from './commonTypes'
|
|
8
|
-
|
|
9
|
-
import { STSDefaultClientToServerEvents, STSDefaultServerToClientEvents } from '@nsshunt/stsobservability'
|
|
10
|
-
|
|
11
|
-
export interface ISocketIoServerHelperOptions {
|
|
12
|
-
logger: ISTSLogger
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export class SocketIoServerHelper<ClientToServerEvents extends STSDefaultClientToServerEvents, ServerToClientEvents extends STSDefaultServerToClientEvents> implements ISocketIoServerHelper<ClientToServerEvents, ServerToClientEvents>
|
|
16
|
-
{
|
|
17
|
-
#socketIoServerHelperOptions: ISocketIoServerHelperOptions
|
|
18
|
-
#namespace: STSSocketIONamespaces = { };
|
|
19
|
-
|
|
20
|
-
constructor(options: ISocketIoServerHelperOptions) { // IProcessBase
|
|
21
|
-
this.#socketIoServerHelperOptions = options;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
LogMessage(namespace: STSSocketIONamespace, message: any) {
|
|
25
|
-
this.#socketIoServerHelperOptions.logger.debug(`${namespace.namespace}: ${message}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
LeaveRoom = (namespace: STSSocketIONamespace, socket: Socket<ClientToServerEvents, ServerToClientEvents>, room: string): void => {
|
|
29
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: Leaving room [${room}]`);
|
|
30
|
-
socket.leave(room);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
JoinRoom = (namespace: STSSocketIONamespace, socket: Socket<ClientToServerEvents, ServerToClientEvents>, room: string): void => {
|
|
34
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: Socket joining room [${room}], ID: [${socket.id}]`);
|
|
35
|
-
socket.join(room);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
#SetupStandardEvents = (namespace: STSSocketIONamespace, socket: Socket<STSDefaultClientToServerEvents, STSDefaultServerToClientEvents>): void => {
|
|
39
|
-
socket.on('disconnect', (reason: string) => {
|
|
40
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
socket.on('disconnecting', (reason: string) => {
|
|
44
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
socket.on('error', (error: Error) => {
|
|
48
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: socket error, ID: [${socket.id}] [${error}]`);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
socket.on("__STSdisconnect", (reason: string) => {
|
|
52
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: __STSdisconnect: socket disconnect, ID: [${socket.id}] [${reason}]`);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
socket.on("__STSdisconnecting", (reason, callBackResult) => {
|
|
56
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}: __STSdisconnecting: socket disconnecting, ID: [${socket.id}] [${reason}]`);
|
|
57
|
-
callBackResult("__STSdisconnecting accepted by server.");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
socket.on('__STSjoinRoom', (rooms: string[]): void => { //@@ names
|
|
61
|
-
rooms.forEach((room) => {
|
|
62
|
-
this.JoinRoom(namespace, socket, room)
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
socket.on('__STSleaveRoom', (rooms: string[]): void => { //@@ names
|
|
67
|
-
rooms.forEach((room) => {
|
|
68
|
-
this.LeaveRoom(namespace, socket, room);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
socket.on('__STSsendToRoom', (rooms: string[], payload: { command: string, payload: JSONObject }): void => {
|
|
73
|
-
rooms.forEach((room) => {
|
|
74
|
-
this.LogMessage(namespace, `${namespace.socketionamespace.name}:socket.on:sendToRoom: __STSsendToRoom: Sending to room [${room}], ID: [${socket.id}]`);
|
|
75
|
-
|
|
76
|
-
namespace.socketionamespace.to(room).emit(payload.command as any, payload);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Use this middleward to check every incomming connection
|
|
82
|
-
#SetupConnectionMiddleware = (nameSpace: STSSocketIONamespace) => {
|
|
83
|
-
nameSpace.socketionamespace.use((socket, next) => {
|
|
84
|
-
//if (isValid(socket.request)) {
|
|
85
|
-
const a=5; // for lint purposes
|
|
86
|
-
if (a === 5) {
|
|
87
|
-
next();
|
|
88
|
-
} else {
|
|
89
|
-
next(new Error("invalid"));
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Use this middleware to check very packet being received
|
|
95
|
-
#SetupMessageMiddleware = (socket: STSServerSocket) => {
|
|
96
|
-
socket.use(([event, ...args], next) => {
|
|
97
|
-
/*
|
|
98
|
-
if (isUnauthorized(event)) {
|
|
99
|
-
return next(new Error("unauthorized event"));
|
|
100
|
-
}
|
|
101
|
-
*/
|
|
102
|
-
next();
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
SetupNamespace = (io: Server, namespace: STSNamespace, rooms: string[], autoJoinRooms: boolean, /* serverSocketEvents: ServerSocketEvent[], */
|
|
107
|
-
socketConnectCallBack: ((socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => void) | null,
|
|
108
|
-
socketEventsCallBack: ((socket: Socket<ClientToServerEvents, ServerToClientEvents, InterServerEvents>) => void) | null
|
|
109
|
-
): Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents> => {
|
|
110
|
-
// Create STS Command Centre Client namespace
|
|
111
|
-
this.#namespace[namespace] = {
|
|
112
|
-
namespace: namespace,
|
|
113
|
-
pid: process.pid,
|
|
114
|
-
socketionamespace: io.of(`/${namespace}/`)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this.#SetupConnectionMiddleware(this.#namespace[namespace]);
|
|
118
|
-
|
|
119
|
-
this.#namespace[namespace].socketionamespace.on("connection", socket => {
|
|
120
|
-
this.LogMessage(this.#namespace[namespace], `${namespace}: Socket connected, ID: [${socket.id}]`);
|
|
121
|
-
this.LogMessage(this.#namespace[namespace], `${namespace}: Authentication Handshake: [${JSON.stringify(socket.handshake.auth)}]`);
|
|
122
|
-
|
|
123
|
-
this.#SetupMessageMiddleware(socket);
|
|
124
|
-
|
|
125
|
-
if (autoJoinRooms) {
|
|
126
|
-
rooms.map((room) => {
|
|
127
|
-
this.JoinRoom(this.#namespace[namespace], socket, room);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
this.#SetupStandardEvents(this.#namespace[namespace], socket);
|
|
132
|
-
|
|
133
|
-
if (socketConnectCallBack) {
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
socketConnectCallBack(socket);
|
|
136
|
-
}, 0);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (socketEventsCallBack) {
|
|
140
|
-
socketEventsCallBack(socket);
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
return this.#namespace[namespace].socketionamespace as Namespace<ClientToServerEvents, ServerToClientEvents, InterServerEvents>;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
GetSTSSocketIONamespace = (namespace: string): STSSocketIONamespace => {
|
|
148
|
-
return this.#namespace[namespace];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
GetSTSSocketIONamespaces = (): STSSocketIONamespaces => {
|
|
152
|
-
return this.#namespace;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
DisconnectSockets = (): void => {
|
|
156
|
-
for (const [, namespace] of Object.entries(this.#namespace)) {
|
|
157
|
-
namespace.socketionamespace.disconnectSockets();
|
|
158
|
-
}
|
|
159
|
-
this.#namespace = { };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
SetupEvent(event: ClientToServerEvents, eventCb: ServerEventCb): ISocketIoServerHelper<ClientToServerEvents, ServerToClientEvents> {
|
|
163
|
-
return this as any;
|
|
164
|
-
}
|
|
165
|
-
}
|
package/src/testHelpers.ts
DELETED
|
@@ -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 './authutilsnode'
|
|
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
|
-
}
|
package/types/authutilsnode.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import tough from 'tough-cookie';
|
|
2
|
-
import { ISTSLogger } from '@nsshunt/stsutils';
|
|
3
|
-
import { PublishInstrumentController } from '@nsshunt/stsobservability';
|
|
4
|
-
export interface IAuthUtilsNodeOptions {
|
|
5
|
-
permissions: string[];
|
|
6
|
-
}
|
|
7
|
-
export interface IGetAPITokenFromAuthServerUsingScopeOptions {
|
|
8
|
-
clientId: string;
|
|
9
|
-
authClientSecret: string;
|
|
10
|
-
scope: string;
|
|
11
|
-
endPoint: string;
|
|
12
|
-
instrumentController?: PublishInstrumentController;
|
|
13
|
-
outputErrorsToConsole?: boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare class AuthUtilsNode {
|
|
16
|
-
#private;
|
|
17
|
-
constructor(logger: ISTSLogger);
|
|
18
|
-
ResetAgent: () => void;
|
|
19
|
-
VerifyRequestMiddlewareFactory: (options: IAuthUtilsNodeOptions) => (req: any, res: any, next: any) => Promise<void>;
|
|
20
|
-
verifyRequestMiddleware(req: any, res: any, next: any): Promise<void>;
|
|
21
|
-
SetCookiesToJar: (headers: Record<string, any>, endpoint: string) => Promise<tough.Cookie[]>;
|
|
22
|
-
GetCookiesFromJar: (endpoint: string) => Promise<tough.Cookie[]>;
|
|
23
|
-
ValidateJWT: (token: string, audience: string, endpoint?: string) => Promise<string>;
|
|
24
|
-
ExtractOrigin: (uri: string) => string | null;
|
|
25
|
-
GetAPITokenFromAuthServerUsingScope: (options: IGetAPITokenFromAuthServerUsingScopeOptions, errorCb: (error: Error) => void) => Promise<string>;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=authutilsnode.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authutilsnode.d.ts","sourceRoot":"","sources":["../src/authutilsnode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAC;AAUjC,OAAO,EAAmB,UAAU,EAAc,MAAM,mBAAmB,CAAA;AAQ3E,OAAO,EAAS,2BAA2B,EAAE,MAAM,2BAA2B,CAAA;AAI9E,MAAM,WAAW,qBAAqB;IAClC,WAAW,EAAE,MAAM,EAAE,CAAA;CACxB;AAED,MAAM,WAAW,2CAA2C;IACxD,QAAQ,EAAE,MAAM,CAAA;IAChB,gBAAgB,EAAE,MAAM,CAAA;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,oBAAoB,CAAC,EAAE,2BAA2B,CAAA;IAClD,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAClC;AAWD,qBAAa,aAAa;;gBAUV,MAAM,EAAE,UAAU;IAyB9B,UAAU,aAET;IAED,8BAA8B,YAAa,qBAAqB,WAEzC,GAAG,OAAO,GAAG,QAAQ,GAAG,mBAyC9C;IAmBK,uBAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAyB3D,eAAe,YAAmB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,YAAY,MAAM,KAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAgB/F;IAEF,iBAAiB,aAAoB,MAAM,KAAG,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAGnE;IAEF,WAAW,UAAiB,MAAM,YAAY,MAAM,aAAa,MAAM,KAAG,OAAO,CAAC,MAAM,CAAC,CAgCxF;IAGD,aAAa,QAAS,MAAM,mBAG3B;IAED,mCAAmC,YAAmB,2CAA2C,WAAW,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,CA6HnJ;CACJ"}
|
package/types/testHelpers.d.ts
DELETED
|
@@ -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"}
|