| 1 | import type { ExecutionContext } from '@nestjs/common'; |
| 2 | import { UnauthorizedException } |
| 3 | import { ConfigService } |
| 4 | import { describe, expect |
| 5 | |
| 6 | import { ImporterSecretGuard } |
| 7 | |
| 8 | const configured = new |
| 9 | IMPORTER_URL: 'http://importer:3004', |
| 10 | IMPORTER_SECRET: 'secret', |
| 11 | GITHUB_CLIENT_ID: 'id', |
| 12 | GITHUB_CLIENT_SECRET: 'client-secret', |
| 13 | }); |
| 14 | |
| 15 | function context(authorization? |
| 16 | return { |
| 17 | switchToHttp: () => |
| 18 | getRequest: () => |
| 19 | }), |
| 20 | } as unknown as |
| 21 | } |
| 22 | |
| 23 | describe('ImporterSecretGuard', () |
| 24 | it('lets the importer in', |
| 25 | expect( |
| 26 | new ImporterSecretGuard(configured |
| 27 | ).toBe(true); |
| 28 | }); |
| 29 | |
| 30 | it('refuses a wrong, missing or malformed secret', |
| 31 | const guard = |
| 32 | for (const header |
| 33 | expect(() => |
| 34 | UnauthorizedException, |
| 35 | ); |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | it('refuses everyone when imports are not configured', |
| 40 | const guard = |
| 41 | expect(() => |
| 42 | UnauthorizedException, |
| 43 | ); |
| 44 | }); |
| 45 | }); |