mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-16 21:19:09 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f78c5a00dd | ||
|
|
ec39b82843 | ||
|
|
20d3532c0f | ||
|
|
9457fcc85e | ||
|
|
1400df0ab9 |
@@ -0,0 +1,57 @@
|
|||||||
|
import { HttpException, HttpStatus } from '@nestjs/common';
|
||||||
|
import { Metadata } from '@grpc/grpc-js';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
|
import { AuthClientService } from './auth.service';
|
||||||
|
|
||||||
|
describe('AuthClientService.resetUsers', () => {
|
||||||
|
const logger = {
|
||||||
|
info: jest.fn(),
|
||||||
|
debug: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
};
|
||||||
|
const resetUser = jest.fn();
|
||||||
|
let service: AuthClientService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
service = new AuthClientService({ logger } as any, {} as any);
|
||||||
|
(service as any).authService = { ResetUser: resetUser };
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the DUC response when every requested user was reset', async () => {
|
||||||
|
const response = {
|
||||||
|
message: 'Users reset successfully',
|
||||||
|
successfulUsers: ['user-1'],
|
||||||
|
failedUsers: [],
|
||||||
|
};
|
||||||
|
resetUser.mockReturnValue(of(response));
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
service.resetUsers(['user-1'], new Metadata()),
|
||||||
|
).resolves.toEqual(response);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a non-2xx error instead of masking failed resets', async () => {
|
||||||
|
const response = {
|
||||||
|
message: 'Some users failed',
|
||||||
|
successfulUsers: ['user-1'],
|
||||||
|
failedUsers: ['user-2'],
|
||||||
|
};
|
||||||
|
resetUser.mockReturnValue(of(response));
|
||||||
|
|
||||||
|
try {
|
||||||
|
await service.resetUsers(['user-1', 'user-2'], new Metadata());
|
||||||
|
fail('Expected resetUsers to reject');
|
||||||
|
} catch (error) {
|
||||||
|
expect(error).toBeInstanceOf(HttpException);
|
||||||
|
expect((error as HttpException).getStatus()).toBe(HttpStatus.BAD_GATEWAY);
|
||||||
|
expect((error as HttpException).getResponse()).toEqual({
|
||||||
|
statusCode: HttpStatus.BAD_GATEWAY,
|
||||||
|
message: 'Failed to reset MFA for one or more users.',
|
||||||
|
successfulUsers: ['user-1'],
|
||||||
|
failedUsers: ['user-2'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -295,6 +295,22 @@ export class AuthClientService implements OnModuleInit {
|
|||||||
this.authService.ResetUser({ users }, metadata),
|
this.authService.ResetUser({ users }, metadata),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (response.failedUsers?.length > 0) {
|
||||||
|
this.logger.error('resetUsers - Partial or total failure', {
|
||||||
|
successfulUsers: response.successfulUsers,
|
||||||
|
failedUsers: response.failedUsers,
|
||||||
|
});
|
||||||
|
throw new HttpException(
|
||||||
|
{
|
||||||
|
statusCode: HttpStatus.BAD_GATEWAY,
|
||||||
|
message: 'Failed to reset MFA for one or more users.',
|
||||||
|
successfulUsers: response.successfulUsers,
|
||||||
|
failedUsers: response.failedUsers,
|
||||||
|
},
|
||||||
|
HttpStatus.BAD_GATEWAY,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.logger.info('resetUsers - Success', { response });
|
this.logger.info('resetUsers - Success', { response });
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -3,11 +3,15 @@ import {
|
|||||||
CdcTable,
|
CdcTable,
|
||||||
} from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities';
|
} from '@dadosfera/protospack-v2/dist/lib/Input/interfaces/entities';
|
||||||
|
|
||||||
/** What a caller knows about a CDC table before it is stored. */
|
/** What a caller knows about a CDC table before it is stored. The source
|
||||||
|
* table is named `table_name` on the platform-facing bodies and `name` on
|
||||||
|
* the create DTO (CdcTableReq); either works — deriving one from the other
|
||||||
|
* happens only here. */
|
||||||
export interface CdcTableInput {
|
export interface CdcTableInput {
|
||||||
// Optional on the create DTO (CdcTableReq); the platform validates it.
|
// Optional on the create DTO (CdcTableReq); the platform validates it.
|
||||||
table_schema?: string;
|
table_schema?: string;
|
||||||
table_name: string;
|
table_name?: string;
|
||||||
|
name?: string;
|
||||||
primary_keys?: string[];
|
primary_keys?: string[];
|
||||||
iceberg_table_name?: string;
|
iceberg_table_name?: string;
|
||||||
iceberg_qualify_table_name?: string;
|
iceberg_qualify_table_name?: string;
|
||||||
@@ -25,10 +29,11 @@ export interface CdcTableInput {
|
|||||||
* `name ?? table_name`).
|
* `name ?? table_name`).
|
||||||
*/
|
*/
|
||||||
export function toCdcTable(table: CdcTableInput): CdcTable {
|
export function toCdcTable(table: CdcTableInput): CdcTable {
|
||||||
|
const tableName = table.table_name ?? table.name;
|
||||||
return {
|
return {
|
||||||
table_schema: table.table_schema,
|
table_schema: table.table_schema,
|
||||||
table_name: table.table_name,
|
table_name: tableName,
|
||||||
name: table.table_name,
|
name: tableName,
|
||||||
primary_keys: table.primary_keys ?? [],
|
primary_keys: table.primary_keys ?? [],
|
||||||
iceberg_table_name: table.iceberg_table_name,
|
iceberg_table_name: table.iceberg_table_name,
|
||||||
iceberg_qualify_table_name: table.iceberg_qualify_table_name,
|
iceberg_qualify_table_name: table.iceberg_qualify_table_name,
|
||||||
|
|||||||
@@ -196,9 +196,7 @@ export class InputsService {
|
|||||||
name: body.name,
|
name: body.name,
|
||||||
plugin: body.plugin,
|
plugin: body.plugin,
|
||||||
read_only: body.read_only ?? true,
|
read_only: body.read_only ?? true,
|
||||||
tables: body.tables.map((t) =>
|
tables: body.tables.map(toCdcTable),
|
||||||
toCdcTable({ ...t, table_name: t.name }),
|
|
||||||
),
|
|
||||||
destination: body.destination,
|
destination: body.destination,
|
||||||
},
|
},
|
||||||
info,
|
info,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ interface PlatformPipeline {
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PipelineTablesService {
|
export class PipelineTablesService {
|
||||||
private logger: DadosferaLogger['logger'];
|
logger: DadosferaLogger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly platformApiService: PlatformApiService,
|
private readonly platformApiService: PlatformApiService,
|
||||||
|
|||||||
Reference in New Issue
Block a user