@gugananuvem/aws-local-simulator 1.0.15 → 1.0.16
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/README.md +789 -594
- package/bin/aws-local-simulator.js +63 -63
- package/package.json +2 -2
- package/src/config/config-loader.js +114 -114
- package/src/config/default-config.js +68 -68
- package/src/config/env-loader.js +68 -68
- package/src/index.js +146 -146
- package/src/index.mjs +123 -123
- package/src/server.js +227 -227
- package/src/services/apigateway/index.js +75 -73
- package/src/services/apigateway/server.js +570 -507
- package/src/services/apigateway/simulator.js +1261 -1261
- package/src/services/athena/index.js +75 -75
- package/src/services/athena/server.js +101 -101
- package/src/services/athena/simulador.js +998 -998
- package/src/services/athena/simulator.js +346 -346
- package/src/services/cloudformation/index.js +106 -106
- package/src/services/cloudformation/server.js +417 -417
- package/src/services/cloudformation/simulador.js +1045 -1045
- package/src/services/cloudtrail/index.js +84 -84
- package/src/services/cloudtrail/server.js +235 -235
- package/src/services/cloudtrail/simulador.js +719 -719
- package/src/services/cloudwatch/index.js +84 -84
- package/src/services/cloudwatch/server.js +366 -366
- package/src/services/cloudwatch/simulador.js +1173 -1173
- package/src/services/cognito/index.js +79 -79
- package/src/services/cognito/server.js +301 -301
- package/src/services/cognito/simulator.js +1655 -1655
- package/src/services/config/index.js +96 -96
- package/src/services/config/server.js +215 -215
- package/src/services/config/simulador.js +1260 -1260
- package/src/services/dynamodb/index.js +74 -74
- package/src/services/dynamodb/server.js +125 -125
- package/src/services/dynamodb/simulator.js +630 -630
- package/src/services/ecs/index.js +65 -65
- package/src/services/ecs/server.js +235 -235
- package/src/services/ecs/simulator.js +844 -844
- package/src/services/eventbridge/index.js +89 -89
- package/src/services/eventbridge/server.js +209 -209
- package/src/services/eventbridge/simulator.js +684 -684
- package/src/services/index.js +45 -45
- package/src/services/kms/index.js +75 -75
- package/src/services/kms/server.js +67 -67
- package/src/services/kms/simulator.js +324 -324
- package/src/services/lambda/handler-loader.js +183 -183
- package/src/services/lambda/index.js +78 -78
- package/src/services/lambda/route-registry.js +274 -274
- package/src/services/lambda/server.js +145 -145
- package/src/services/lambda/simulator.js +199 -199
- package/src/services/parameter-store/index.js +80 -80
- package/src/services/parameter-store/server.js +50 -50
- package/src/services/parameter-store/simulator.js +201 -201
- package/src/services/s3/index.js +73 -73
- package/src/services/s3/server.js +329 -329
- package/src/services/s3/simulator.js +565 -565
- package/src/services/secret-manager/index.js +80 -80
- package/src/services/secret-manager/server.js +50 -50
- package/src/services/secret-manager/simulator.js +171 -171
- package/src/services/sns/index.js +89 -89
- package/src/services/sns/server.js +580 -580
- package/src/services/sns/simulator.js +1482 -1482
- package/src/services/sqs/index.js +98 -93
- package/src/services/sqs/server.js +349 -349
- package/src/services/sqs/simulator.js +441 -441
- package/src/services/sts/index.js +37 -37
- package/src/services/sts/server.js +144 -144
- package/src/services/sts/simulator.js +69 -69
- package/src/services/xray/index.js +83 -83
- package/src/services/xray/server.js +308 -308
- package/src/services/xray/simulador.js +994 -994
- package/src/template/aws-config-template.js +87 -87
- package/src/template/aws-config-template.mjs +90 -90
- package/src/template/config-template.json +203 -203
- package/src/utils/aws-config.js +91 -91
- package/src/utils/cloudtrail-audit.js +129 -129
- package/src/utils/local-store.js +83 -83
- package/src/utils/logger.js +59 -59
|
@@ -1,302 +1,302 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cognito Server - Servidor HTTP para Cognito API
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const express = require('express');
|
|
6
|
-
const cors = require('cors');
|
|
7
|
-
const logger = require('../../utils/logger');
|
|
8
|
-
|
|
9
|
-
class CognitoServer {
|
|
10
|
-
constructor(port, config) {
|
|
11
|
-
this.port = port;
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.app = express();
|
|
14
|
-
this.simulator = null;
|
|
15
|
-
this.server = null;
|
|
16
|
-
this.setupMiddlewares();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
setupMiddlewares() {
|
|
20
|
-
this.app.use(cors());
|
|
21
|
-
this.app.use(express.raw({ type: '*/*', limit: '10mb' }));
|
|
22
|
-
this.app.use((req, res, next) => {
|
|
23
|
-
if (req.body && Buffer.isBuffer(req.body)) {
|
|
24
|
-
try {
|
|
25
|
-
req.body = JSON.parse(req.body.toString('utf8'));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
req.body = {};
|
|
28
|
-
}
|
|
29
|
-
} else if (!req.body) {
|
|
30
|
-
req.body = {};
|
|
31
|
-
}
|
|
32
|
-
next();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (logger.currentLogLevel === 'verboso') {
|
|
36
|
-
this.app.use((req, res, next) => {
|
|
37
|
-
const start = Date.now();
|
|
38
|
-
res.on('finish', () => {
|
|
39
|
-
const duration = Date.now() - start;
|
|
40
|
-
logger.verboso(`Cognito: ${req.method} ${req.path} - ${duration}ms`);
|
|
41
|
-
});
|
|
42
|
-
next();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async initialize() {
|
|
48
|
-
this.setupRoutes();
|
|
49
|
-
logger.debug('Cognito Server inicializado');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setupRoutes() {
|
|
53
|
-
// Health check
|
|
54
|
-
this.app.get('/health', (req, res) => {
|
|
55
|
-
res.json({
|
|
56
|
-
status: 'healthy',
|
|
57
|
-
service: 'cognito-simulator',
|
|
58
|
-
version: '1.0.0'
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
// User Pool operations — aceita POST / e POST /:userPoolId (compatibilidade com SDK)
|
|
63
|
-
const cognitoHandler = async (req, res) => {
|
|
64
|
-
const target = req.headers['x-amz-target'];
|
|
65
|
-
logger.info(`Cognito incoming: method=${req.method} path=${req.path} target=${target} body=${JSON.stringify(req.body)}`);
|
|
66
|
-
|
|
67
|
-
if (!target) {
|
|
68
|
-
return res.status(400).json({
|
|
69
|
-
__type: 'InvalidParameterException',
|
|
70
|
-
message: 'Missing X-Amz-Target header'
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
const result = await this.handleRequest(target, req.body || {});
|
|
76
|
-
res.json(result);
|
|
77
|
-
} catch (error) {
|
|
78
|
-
logger.error('Cognito Error:', error.message);
|
|
79
|
-
res.status(400).json({
|
|
80
|
-
__type: error.code || 'InternalServerError',
|
|
81
|
-
message: error.message
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
// OPTIONS preflight para CORS
|
|
87
|
-
this.app.options('*', (req, res) => res.sendStatus(204));
|
|
88
|
-
|
|
89
|
-
this.app.post('/', cognitoHandler);
|
|
90
|
-
this.app.post('/:userPoolId', cognitoHandler);
|
|
91
|
-
|
|
92
|
-
// Admin endpoints
|
|
93
|
-
this.setupAdminRoutes();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async handleRequest(target, params) {
|
|
97
|
-
const action = target.split('.')[2] || target.split('.')[1];
|
|
98
|
-
|
|
99
|
-
logger.verboso(`Cognito Action: ${action}`);
|
|
100
|
-
|
|
101
|
-
switch(action) {
|
|
102
|
-
// User Pool Management
|
|
103
|
-
case 'CreateUserPool':
|
|
104
|
-
return this.simulator.createUserPool(params);
|
|
105
|
-
case 'ListUserPools':
|
|
106
|
-
return this.simulator.listUserPools(params);
|
|
107
|
-
case 'DescribeUserPool':
|
|
108
|
-
return this.simulator.describeUserPool(params);
|
|
109
|
-
case 'DeleteUserPool':
|
|
110
|
-
return this.simulator.deleteUserPool(params);
|
|
111
|
-
|
|
112
|
-
case 'ListUsers':
|
|
113
|
-
return this.simulator.listUsers(params);
|
|
114
|
-
// User Pool Client Management
|
|
115
|
-
case 'CreateUserPoolClient':
|
|
116
|
-
return this.simulator.createUserPoolClient(params);
|
|
117
|
-
case 'ListUserPoolClients':
|
|
118
|
-
return this.simulator.listUserPoolClients(params);
|
|
119
|
-
case 'DescribeUserPoolClient':
|
|
120
|
-
return this.simulator.describeUserPoolClient(params);
|
|
121
|
-
case 'DeleteUserPoolClient':
|
|
122
|
-
return this.simulator.deleteUserPoolClient(params);
|
|
123
|
-
|
|
124
|
-
// User Operations
|
|
125
|
-
case 'SignUp':
|
|
126
|
-
return this.simulator.signUp(params);
|
|
127
|
-
case 'ConfirmSignUp':
|
|
128
|
-
return this.simulator.confirmSignUp(params);
|
|
129
|
-
case 'ForgotPassword':
|
|
130
|
-
return this.simulator.forgotPassword(params);
|
|
131
|
-
case 'ConfirmForgotPassword':
|
|
132
|
-
return this.simulator.confirmForgotPassword(params);
|
|
133
|
-
case 'ChangePassword':
|
|
134
|
-
return this.simulator.changePassword(params);
|
|
135
|
-
case 'InitiateAuth':
|
|
136
|
-
return this.simulator.initiateAuth(params);
|
|
137
|
-
case 'RespondToAuthChallenge':
|
|
138
|
-
return this.simulator.respondToAuthChallenge(params);
|
|
139
|
-
case 'GetToken':
|
|
140
|
-
return this.simulator.getToken(params);
|
|
141
|
-
case 'GlobalSignOut':
|
|
142
|
-
return this.simulator.globalSignOut(params);
|
|
143
|
-
case 'RevokeToken':
|
|
144
|
-
return this.simulator.revokeToken(params);
|
|
145
|
-
case 'GetUser':
|
|
146
|
-
return this.simulator.getUser(params);
|
|
147
|
-
case 'UpdateUserAttributes':
|
|
148
|
-
return this.simulator.updateUserAttributes(params);
|
|
149
|
-
case 'DeleteUser':
|
|
150
|
-
return this.simulator.deleteUser(params);
|
|
151
|
-
|
|
152
|
-
// Admin Operations
|
|
153
|
-
case 'AdminGetUser':
|
|
154
|
-
return this.simulator.adminGetUser(params);
|
|
155
|
-
case 'AdminCreateUser':
|
|
156
|
-
return this.simulator.adminCreateUser(params);
|
|
157
|
-
case 'AdminSetUserPassword':
|
|
158
|
-
return this.simulator.adminSetUserPassword(params);
|
|
159
|
-
case 'AdminDeleteUser':
|
|
160
|
-
return this.simulator.adminDeleteUser(params);
|
|
161
|
-
case 'AdminDisableUser':
|
|
162
|
-
return this.simulator.adminDisableUser(params);
|
|
163
|
-
case 'AdminEnableUser':
|
|
164
|
-
return this.simulator.adminEnableUser(params);
|
|
165
|
-
case 'AdminResetUserPassword':
|
|
166
|
-
return this.simulator.adminResetUserPassword(params);
|
|
167
|
-
case 'AdminInitiateAuth':
|
|
168
|
-
return this.simulator.initiateAuth(params);
|
|
169
|
-
case 'AdminListGroupsForUser':
|
|
170
|
-
return this.simulator.adminListGroupsForUser(params);
|
|
171
|
-
case 'AdminUserGlobalSignOut':
|
|
172
|
-
return this.simulator.adminUserGlobalSignOut(params);
|
|
173
|
-
|
|
174
|
-
// Identity Pool Operations
|
|
175
|
-
case 'CreateIdentityPool':
|
|
176
|
-
return this.simulator.createIdentityPool(params);
|
|
177
|
-
case 'GetId':
|
|
178
|
-
return this.simulator.getId(params);
|
|
179
|
-
case 'GetCredentialsForIdentity':
|
|
180
|
-
return this.simulator.getCredentialsForIdentity(params);
|
|
181
|
-
|
|
182
|
-
default:
|
|
183
|
-
throw new Error(`Unsupported action: ${action}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
setupAdminRoutes() {
|
|
188
|
-
this.app.get('/__admin/userpools', (req, res) => {
|
|
189
|
-
res.json({
|
|
190
|
-
userPools: this.simulator.getUserPoolsCount(),
|
|
191
|
-
users: this.simulator.getTotalUsersCount(),
|
|
192
|
-
identityPools: this.simulator.getIdentityPoolsCount(),
|
|
193
|
-
activeSessions: this.simulator.getActiveSessionsCount()
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// Confirma um usuário (útil para dev local)
|
|
198
|
-
this.app.post('/__admin/userpools/:poolId/users/:username/confirm', (req, res) => {
|
|
199
|
-
const user = this.simulator.findUserByUsername(req.params.username, null, req.params.poolId);
|
|
200
|
-
if (!user) return res.status(404).json({ error: 'User not found' });
|
|
201
|
-
user.UserStatus = 'CONFIRMED';
|
|
202
|
-
user.LastModifiedDate = new Date().toISOString();
|
|
203
|
-
this.simulator.persistUsers();
|
|
204
|
-
res.json({ message: `User ${req.params.username} confirmed` });
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
this.app.get('/__admin/userpools/:poolId/users', (req, res) => {
|
|
208
|
-
const pool = this.simulator.userPools.get(req.params.poolId);
|
|
209
|
-
if (!pool) {
|
|
210
|
-
return res.status(404).json({ error: 'User pool not found' });
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const users = [];
|
|
214
|
-
for (const userId of pool.Users) {
|
|
215
|
-
const user = this.simulator.users.get(userId);
|
|
216
|
-
if (user) {
|
|
217
|
-
users.push({
|
|
218
|
-
username: user.Username,
|
|
219
|
-
userId: user.UserId,
|
|
220
|
-
status: user.UserStatus,
|
|
221
|
-
attributes: user.Attributes,
|
|
222
|
-
created: user.CreatedDate
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
res.json(users);
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
this.app.get('/__admin/validate-token', (req, res) => {
|
|
231
|
-
const authHeader = req.headers.authorization;
|
|
232
|
-
if (!authHeader) {
|
|
233
|
-
return res.status(401).json({ error: 'No token provided' });
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const token = authHeader.replace('Bearer ', '');
|
|
237
|
-
const decoded = this.simulator.verifyAccessToken(token);
|
|
238
|
-
|
|
239
|
-
if (!decoded) {
|
|
240
|
-
return res.status(401).json({ error: 'Invalid token' });
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
res.json({ valid: true, payload: decoded });
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
this.app.post('/__admin/generate-token', (req, res) => {
|
|
247
|
-
const { username, userPoolId, clientId } = req.body;
|
|
248
|
-
|
|
249
|
-
const userPool = this.simulator.userPools.get(userPoolId);
|
|
250
|
-
if (!userPool) {
|
|
251
|
-
return res.status(404).json({ error: 'User pool not found' });
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const user = this.simulator.findUserByUsername(username, null, userPoolId);
|
|
255
|
-
if (!user) {
|
|
256
|
-
return res.status(404).json({ error: 'User not found' });
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const accessToken = this.simulator.generateAccessToken(user, userPool, clientId);
|
|
260
|
-
const idToken = this.simulator.generateIdToken(user, userPool, clientId);
|
|
261
|
-
|
|
262
|
-
res.json({
|
|
263
|
-
accessToken,
|
|
264
|
-
idToken,
|
|
265
|
-
expiresIn: 3600
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
start() {
|
|
271
|
-
return new Promise((resolve) => {
|
|
272
|
-
this.server = this.app.listen(this.port, () => {
|
|
273
|
-
logger.info(`🔐 Cognito rodando em http://localhost:${this.port}`);
|
|
274
|
-
resolve();
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
stop() {
|
|
280
|
-
return new Promise((resolve) => {
|
|
281
|
-
if (this.server) {
|
|
282
|
-
this.server.close(() => resolve());
|
|
283
|
-
} else {
|
|
284
|
-
resolve();
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
getStatus() {
|
|
290
|
-
return {
|
|
291
|
-
running: !!this.server,
|
|
292
|
-
port: this.port,
|
|
293
|
-
endpoint: `http://localhost:${this.port}`,
|
|
294
|
-
userPoolsCount: this.simulator?.getUserPoolsCount() || 0,
|
|
295
|
-
usersCount: this.simulator?.getTotalUsersCount() || 0,
|
|
296
|
-
identityPoolsCount: this.simulator?.getIdentityPoolsCount() || 0,
|
|
297
|
-
activeSessions: this.simulator?.getActiveSessionsCount() || 0
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Cognito Server - Servidor HTTP para Cognito API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const express = require('express');
|
|
6
|
+
const cors = require('cors');
|
|
7
|
+
const logger = require('../../utils/logger');
|
|
8
|
+
|
|
9
|
+
class CognitoServer {
|
|
10
|
+
constructor(port, config) {
|
|
11
|
+
this.port = port;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.app = express();
|
|
14
|
+
this.simulator = null;
|
|
15
|
+
this.server = null;
|
|
16
|
+
this.setupMiddlewares();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
setupMiddlewares() {
|
|
20
|
+
this.app.use(cors());
|
|
21
|
+
this.app.use(express.raw({ type: '*/*', limit: '10mb' }));
|
|
22
|
+
this.app.use((req, res, next) => {
|
|
23
|
+
if (req.body && Buffer.isBuffer(req.body)) {
|
|
24
|
+
try {
|
|
25
|
+
req.body = JSON.parse(req.body.toString('utf8'));
|
|
26
|
+
} catch (e) {
|
|
27
|
+
req.body = {};
|
|
28
|
+
}
|
|
29
|
+
} else if (!req.body) {
|
|
30
|
+
req.body = {};
|
|
31
|
+
}
|
|
32
|
+
next();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (logger.currentLogLevel === 'verboso') {
|
|
36
|
+
this.app.use((req, res, next) => {
|
|
37
|
+
const start = Date.now();
|
|
38
|
+
res.on('finish', () => {
|
|
39
|
+
const duration = Date.now() - start;
|
|
40
|
+
logger.verboso(`Cognito: ${req.method} ${req.path} - ${duration}ms`);
|
|
41
|
+
});
|
|
42
|
+
next();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async initialize() {
|
|
48
|
+
this.setupRoutes();
|
|
49
|
+
logger.debug('Cognito Server inicializado');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setupRoutes() {
|
|
53
|
+
// Health check
|
|
54
|
+
this.app.get('/health', (req, res) => {
|
|
55
|
+
res.json({
|
|
56
|
+
status: 'healthy',
|
|
57
|
+
service: 'cognito-simulator',
|
|
58
|
+
version: '1.0.0'
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// User Pool operations — aceita POST / e POST /:userPoolId (compatibilidade com SDK)
|
|
63
|
+
const cognitoHandler = async (req, res) => {
|
|
64
|
+
const target = req.headers['x-amz-target'];
|
|
65
|
+
logger.info(`Cognito incoming: method=${req.method} path=${req.path} target=${target} body=${JSON.stringify(req.body)}`);
|
|
66
|
+
|
|
67
|
+
if (!target) {
|
|
68
|
+
return res.status(400).json({
|
|
69
|
+
__type: 'InvalidParameterException',
|
|
70
|
+
message: 'Missing X-Amz-Target header'
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const result = await this.handleRequest(target, req.body || {});
|
|
76
|
+
res.json(result);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
logger.error('Cognito Error:', error.message);
|
|
79
|
+
res.status(400).json({
|
|
80
|
+
__type: error.code || 'InternalServerError',
|
|
81
|
+
message: error.message
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// OPTIONS preflight para CORS
|
|
87
|
+
this.app.options('*', (req, res) => res.sendStatus(204));
|
|
88
|
+
|
|
89
|
+
this.app.post('/', cognitoHandler);
|
|
90
|
+
this.app.post('/:userPoolId', cognitoHandler);
|
|
91
|
+
|
|
92
|
+
// Admin endpoints
|
|
93
|
+
this.setupAdminRoutes();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async handleRequest(target, params) {
|
|
97
|
+
const action = target.split('.')[2] || target.split('.')[1];
|
|
98
|
+
|
|
99
|
+
logger.verboso(`Cognito Action: ${action}`);
|
|
100
|
+
|
|
101
|
+
switch(action) {
|
|
102
|
+
// User Pool Management
|
|
103
|
+
case 'CreateUserPool':
|
|
104
|
+
return this.simulator.createUserPool(params);
|
|
105
|
+
case 'ListUserPools':
|
|
106
|
+
return this.simulator.listUserPools(params);
|
|
107
|
+
case 'DescribeUserPool':
|
|
108
|
+
return this.simulator.describeUserPool(params);
|
|
109
|
+
case 'DeleteUserPool':
|
|
110
|
+
return this.simulator.deleteUserPool(params);
|
|
111
|
+
|
|
112
|
+
case 'ListUsers':
|
|
113
|
+
return this.simulator.listUsers(params);
|
|
114
|
+
// User Pool Client Management
|
|
115
|
+
case 'CreateUserPoolClient':
|
|
116
|
+
return this.simulator.createUserPoolClient(params);
|
|
117
|
+
case 'ListUserPoolClients':
|
|
118
|
+
return this.simulator.listUserPoolClients(params);
|
|
119
|
+
case 'DescribeUserPoolClient':
|
|
120
|
+
return this.simulator.describeUserPoolClient(params);
|
|
121
|
+
case 'DeleteUserPoolClient':
|
|
122
|
+
return this.simulator.deleteUserPoolClient(params);
|
|
123
|
+
|
|
124
|
+
// User Operations
|
|
125
|
+
case 'SignUp':
|
|
126
|
+
return this.simulator.signUp(params);
|
|
127
|
+
case 'ConfirmSignUp':
|
|
128
|
+
return this.simulator.confirmSignUp(params);
|
|
129
|
+
case 'ForgotPassword':
|
|
130
|
+
return this.simulator.forgotPassword(params);
|
|
131
|
+
case 'ConfirmForgotPassword':
|
|
132
|
+
return this.simulator.confirmForgotPassword(params);
|
|
133
|
+
case 'ChangePassword':
|
|
134
|
+
return this.simulator.changePassword(params);
|
|
135
|
+
case 'InitiateAuth':
|
|
136
|
+
return this.simulator.initiateAuth(params);
|
|
137
|
+
case 'RespondToAuthChallenge':
|
|
138
|
+
return this.simulator.respondToAuthChallenge(params);
|
|
139
|
+
case 'GetToken':
|
|
140
|
+
return this.simulator.getToken(params);
|
|
141
|
+
case 'GlobalSignOut':
|
|
142
|
+
return this.simulator.globalSignOut(params);
|
|
143
|
+
case 'RevokeToken':
|
|
144
|
+
return this.simulator.revokeToken(params);
|
|
145
|
+
case 'GetUser':
|
|
146
|
+
return this.simulator.getUser(params);
|
|
147
|
+
case 'UpdateUserAttributes':
|
|
148
|
+
return this.simulator.updateUserAttributes(params);
|
|
149
|
+
case 'DeleteUser':
|
|
150
|
+
return this.simulator.deleteUser(params);
|
|
151
|
+
|
|
152
|
+
// Admin Operations
|
|
153
|
+
case 'AdminGetUser':
|
|
154
|
+
return this.simulator.adminGetUser(params);
|
|
155
|
+
case 'AdminCreateUser':
|
|
156
|
+
return this.simulator.adminCreateUser(params);
|
|
157
|
+
case 'AdminSetUserPassword':
|
|
158
|
+
return this.simulator.adminSetUserPassword(params);
|
|
159
|
+
case 'AdminDeleteUser':
|
|
160
|
+
return this.simulator.adminDeleteUser(params);
|
|
161
|
+
case 'AdminDisableUser':
|
|
162
|
+
return this.simulator.adminDisableUser(params);
|
|
163
|
+
case 'AdminEnableUser':
|
|
164
|
+
return this.simulator.adminEnableUser(params);
|
|
165
|
+
case 'AdminResetUserPassword':
|
|
166
|
+
return this.simulator.adminResetUserPassword(params);
|
|
167
|
+
case 'AdminInitiateAuth':
|
|
168
|
+
return this.simulator.initiateAuth(params);
|
|
169
|
+
case 'AdminListGroupsForUser':
|
|
170
|
+
return this.simulator.adminListGroupsForUser(params);
|
|
171
|
+
case 'AdminUserGlobalSignOut':
|
|
172
|
+
return this.simulator.adminUserGlobalSignOut(params);
|
|
173
|
+
|
|
174
|
+
// Identity Pool Operations
|
|
175
|
+
case 'CreateIdentityPool':
|
|
176
|
+
return this.simulator.createIdentityPool(params);
|
|
177
|
+
case 'GetId':
|
|
178
|
+
return this.simulator.getId(params);
|
|
179
|
+
case 'GetCredentialsForIdentity':
|
|
180
|
+
return this.simulator.getCredentialsForIdentity(params);
|
|
181
|
+
|
|
182
|
+
default:
|
|
183
|
+
throw new Error(`Unsupported action: ${action}`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
setupAdminRoutes() {
|
|
188
|
+
this.app.get('/__admin/userpools', (req, res) => {
|
|
189
|
+
res.json({
|
|
190
|
+
userPools: this.simulator.getUserPoolsCount(),
|
|
191
|
+
users: this.simulator.getTotalUsersCount(),
|
|
192
|
+
identityPools: this.simulator.getIdentityPoolsCount(),
|
|
193
|
+
activeSessions: this.simulator.getActiveSessionsCount()
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Confirma um usuário (útil para dev local)
|
|
198
|
+
this.app.post('/__admin/userpools/:poolId/users/:username/confirm', (req, res) => {
|
|
199
|
+
const user = this.simulator.findUserByUsername(req.params.username, null, req.params.poolId);
|
|
200
|
+
if (!user) return res.status(404).json({ error: 'User not found' });
|
|
201
|
+
user.UserStatus = 'CONFIRMED';
|
|
202
|
+
user.LastModifiedDate = new Date().toISOString();
|
|
203
|
+
this.simulator.persistUsers();
|
|
204
|
+
res.json({ message: `User ${req.params.username} confirmed` });
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
this.app.get('/__admin/userpools/:poolId/users', (req, res) => {
|
|
208
|
+
const pool = this.simulator.userPools.get(req.params.poolId);
|
|
209
|
+
if (!pool) {
|
|
210
|
+
return res.status(404).json({ error: 'User pool not found' });
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const users = [];
|
|
214
|
+
for (const userId of pool.Users) {
|
|
215
|
+
const user = this.simulator.users.get(userId);
|
|
216
|
+
if (user) {
|
|
217
|
+
users.push({
|
|
218
|
+
username: user.Username,
|
|
219
|
+
userId: user.UserId,
|
|
220
|
+
status: user.UserStatus,
|
|
221
|
+
attributes: user.Attributes,
|
|
222
|
+
created: user.CreatedDate
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
res.json(users);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
this.app.get('/__admin/validate-token', (req, res) => {
|
|
231
|
+
const authHeader = req.headers.authorization;
|
|
232
|
+
if (!authHeader) {
|
|
233
|
+
return res.status(401).json({ error: 'No token provided' });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const token = authHeader.replace('Bearer ', '');
|
|
237
|
+
const decoded = this.simulator.verifyAccessToken(token);
|
|
238
|
+
|
|
239
|
+
if (!decoded) {
|
|
240
|
+
return res.status(401).json({ error: 'Invalid token' });
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
res.json({ valid: true, payload: decoded });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
this.app.post('/__admin/generate-token', (req, res) => {
|
|
247
|
+
const { username, userPoolId, clientId } = req.body;
|
|
248
|
+
|
|
249
|
+
const userPool = this.simulator.userPools.get(userPoolId);
|
|
250
|
+
if (!userPool) {
|
|
251
|
+
return res.status(404).json({ error: 'User pool not found' });
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const user = this.simulator.findUserByUsername(username, null, userPoolId);
|
|
255
|
+
if (!user) {
|
|
256
|
+
return res.status(404).json({ error: 'User not found' });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const accessToken = this.simulator.generateAccessToken(user, userPool, clientId);
|
|
260
|
+
const idToken = this.simulator.generateIdToken(user, userPool, clientId);
|
|
261
|
+
|
|
262
|
+
res.json({
|
|
263
|
+
accessToken,
|
|
264
|
+
idToken,
|
|
265
|
+
expiresIn: 3600
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
start() {
|
|
271
|
+
return new Promise((resolve) => {
|
|
272
|
+
this.server = this.app.listen(this.port, () => {
|
|
273
|
+
logger.info(`🔐 Cognito rodando em http://localhost:${this.port}`);
|
|
274
|
+
resolve();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
stop() {
|
|
280
|
+
return new Promise((resolve) => {
|
|
281
|
+
if (this.server) {
|
|
282
|
+
this.server.close(() => resolve());
|
|
283
|
+
} else {
|
|
284
|
+
resolve();
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
getStatus() {
|
|
290
|
+
return {
|
|
291
|
+
running: !!this.server,
|
|
292
|
+
port: this.port,
|
|
293
|
+
endpoint: `http://localhost:${this.port}`,
|
|
294
|
+
userPoolsCount: this.simulator?.getUserPoolsCount() || 0,
|
|
295
|
+
usersCount: this.simulator?.getTotalUsersCount() || 0,
|
|
296
|
+
identityPoolsCount: this.simulator?.getIdentityPoolsCount() || 0,
|
|
297
|
+
activeSessions: this.simulator?.getActiveSessionsCount() || 0
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
302
|
module.exports = CognitoServer;
|