-
Notifications
You must be signed in to change notification settings - Fork 1
LIME-2122 - Added Template Tests for CloudFormation Templates #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { readFileSync } from 'node:fs' | ||
| import { resolve } from 'node:path' | ||
| import { parse } from 'yaml' | ||
| import { z } from 'zod' | ||
|
|
||
| const cfnTagNames = [ | ||
| 'And', | ||
| 'Base64', | ||
| 'Cidr', | ||
| 'Condition', | ||
| 'Equals', | ||
| 'FindInMap', | ||
| 'GetAtt', | ||
| 'GetAZs', | ||
| 'If', | ||
| 'ImportValue', | ||
| 'Join', | ||
| 'Not', | ||
| 'Or', | ||
| 'Ref', | ||
| 'Select', | ||
| 'Split', | ||
| 'Sub', | ||
| 'Transform' | ||
| ] | ||
| const cfnTags = cfnTagNames.flatMap((name) => [ | ||
| { collection: 'seq' as const, resolve: (seq: unknown) => seq, tag: `!${name}` }, | ||
| { resolve: (str: string) => str, tag: `!${name}` } | ||
| ]) | ||
|
|
||
| export const loadTemplate = (relativePath: string): Record<string, unknown> => | ||
| parse(readFileSync(resolve(__dirname, '../../deploy', relativePath), 'utf-8'), { | ||
| customTags: cfnTags | ||
| }) as Record<string, unknown> | ||
|
|
||
| // Common CloudFormation schemas | ||
| export const cfnParameterSchema = z.object({ | ||
| AllowedValues: z.array(z.string()).optional(), | ||
| Default: z.union([z.string(), z.number()]).optional(), | ||
| Description: z.string().optional(), | ||
| Type: z.string() | ||
| }) | ||
|
|
||
| export const cfnOutputSchema = z.object({ | ||
| Condition: z.string().optional(), | ||
| Description: z.string().optional(), | ||
| Export: z.object({ Name: z.unknown() }).optional(), | ||
| Value: z.unknown() | ||
| }) | ||
|
|
||
| export const openApiSchema = z.object({ | ||
| info: z.object({ | ||
| title: z.string(), | ||
| version: z.string() | ||
| }), | ||
| openapi: z.string().regex(/^3\.\d+\.\d+$/), | ||
| paths: z.record(z.string(), z.record(z.string(), z.unknown())) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { loadTemplate, openApiSchema } from './helpers' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| const template = loadTemplate('private-api.yaml') | ||
|
|
||
| const paths = template['paths'] as Record<string, Record<string, unknown>> | ||
|
|
||
| describe('private-api.yaml structure', () => { | ||
| it('is a valid OpenAPI 3.x document', () => { | ||
| expect(openApiSchema.safeParse(template).success).toBe(true) | ||
| }) | ||
|
|
||
| it('has title', () => { | ||
| const info = template['info'] as Record<string, string> | ||
| expect(info['title']).toBe('Open Banking Credential Issuer Private API') | ||
| }) | ||
| }) | ||
|
|
||
| describe('private-api.yaml paths', () => { | ||
| const expectedPaths = ['/basic-function', '/authorization', '/session'] | ||
|
|
||
| it.each(expectedPaths)('has path: %s', (path) => { | ||
| expect(paths).toHaveProperty(path) | ||
| }) | ||
|
|
||
| it('/basic-function has POST with aws_proxy integration', () => { | ||
| const post = paths['/basic-function']?.['post'] as Record<string, unknown> | ||
| const integration = post['x-amazon-apigateway-integration'] as Record<string, string> | ||
| expect(integration['type']).toBe('aws_proxy') | ||
| }) | ||
|
|
||
| it('/authorization has GET method', () => { | ||
| expect(paths['/authorization']).toHaveProperty('get') | ||
| }) | ||
|
|
||
| it('/session has POST method', () => { | ||
| expect(paths['/session']).toHaveProperty('post') | ||
| }) | ||
| }) | ||
|
|
||
| describe('private-api.yaml components', () => { | ||
| const components = template['components'] as Record<string, Record<string, unknown>> | ||
|
|
||
| it('defines SessionHeader parameter', () => { | ||
| expect(components['parameters']).toHaveProperty('SessionHeader') | ||
| }) | ||
|
|
||
| it('defines required schemas', () => { | ||
| const schemas = components['schemas'] | ||
| expect(schemas).toHaveProperty('Authorization') | ||
| expect(schemas).toHaveProperty('AuthorizationResponse') | ||
| expect(schemas).toHaveProperty('Error') | ||
| expect(schemas).toHaveProperty('Session') | ||
| }) | ||
| }) | ||
|
|
||
| describe('private-api.yaml request validators', () => { | ||
| const validators = template['x-amazon-apigateway-request-validators'] as Record<string, unknown> | ||
|
|
||
| it('defines Validate both', () => { | ||
| expect(validators).toHaveProperty('Validate both') | ||
| }) | ||
|
|
||
| it('defines Validate Param only', () => { | ||
| expect(validators).toHaveProperty('Validate Param only') | ||
| }) | ||
| }) | ||
|
|
||
| describe('private-api.yaml route validator assignments', () => { | ||
| it('/authorization applies Validate both', () => { | ||
| const get = paths['/authorization']?.['get'] as Record<string, unknown> | ||
| expect(get['x-amazon-apigateway-request-validator']).toBe('Validate both') | ||
| }) | ||
|
|
||
| it('/session applies Validate both', () => { | ||
| const post = paths['/session']?.['post'] as Record<string, unknown> | ||
| expect(post['x-amazon-apigateway-request-validator']).toBe('Validate both') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import { loadTemplate, openApiSchema } from './helpers' | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| const template = loadTemplate('public-api.yaml') | ||
|
|
||
| const paths = template['paths'] as Record<string, Record<string, unknown>> | ||
|
|
||
| describe('public-api.yaml structure', () => { | ||
| it('is a valid OpenAPI 3.x document', () => { | ||
| expect(openApiSchema.safeParse(template).success).toBe(true) | ||
| }) | ||
|
|
||
| it('has title', () => { | ||
| const info = template['info'] as Record<string, string> | ||
| expect(info['title']).toBe('Open Banking Credential Issuer Public API') | ||
| }) | ||
| }) | ||
|
|
||
| describe('public-api.yaml paths', () => { | ||
| const expectedPaths = ['/health', '/.well-known/jwks.json', '/token'] | ||
|
|
||
| it.each(expectedPaths)('has path: %s', (path) => { | ||
| expect(paths).toHaveProperty(path) | ||
| }) | ||
|
|
||
| it('/health has GET with mock integration', () => { | ||
| const get = paths['/health']?.['get'] as Record<string, unknown> | ||
| const integration = get['x-amazon-apigateway-integration'] as Record<string, string> | ||
| expect(integration['type']).toBe('mock') | ||
| }) | ||
|
|
||
| it('/token has POST method', () => { | ||
| expect(paths['/token']).toHaveProperty('post') | ||
| }) | ||
|
|
||
| it('/.well-known/jwks.json has GET with S3 integration', () => { | ||
| const get = paths['/.well-known/jwks.json']?.['get'] as Record<string, unknown> | ||
| const integration = get['x-amazon-apigateway-integration'] as Record<string, string> | ||
| expect(integration['type']).toBe('aws') | ||
| }) | ||
| }) | ||
|
|
||
| describe('public-api.yaml components', () => { | ||
| const components = template['components'] as Record<string, Record<string, unknown>> | ||
| const schemas = components['schemas'] | ||
|
|
||
| it('defines required schemas', () => { | ||
| expect(schemas).toHaveProperty('JWKSFile') | ||
| expect(schemas).toHaveProperty('TokenResponse') | ||
| expect(schemas).toHaveProperty('Error') | ||
| }) | ||
| }) | ||
|
|
||
| describe('public-api.yaml request validators', () => { | ||
| const validators = template['x-amazon-apigateway-request-validators'] as Record<string, unknown> | ||
|
|
||
| it('defines Validate both', () => { | ||
| expect(validators).toHaveProperty('Validate both') | ||
| }) | ||
|
|
||
| it('defines Validate Param only', () => { | ||
| expect(validators).toHaveProperty('Validate Param only') | ||
| }) | ||
| }) | ||
|
|
||
| describe('public-api.yaml /token security and validation', () => { | ||
| const post = paths['/token']?.['post'] as Record<string, unknown> | ||
|
|
||
| it('applies Validate both request validator', () => { | ||
| expect(post['x-amazon-apigateway-request-validator']).toBe('Validate both') | ||
| }) | ||
|
|
||
| it('has api_key security requirement', () => { | ||
| const security = post['security'] as Record<string, unknown>[] | ||
| expect(security).toBeDefined() | ||
| expect(security.some((s) => 'api_key' in s)).toBe(true) | ||
| }) | ||
|
|
||
| it('uses aws_proxy integration', () => { | ||
| const integration = post['x-amazon-apigateway-integration'] as Record<string, string> | ||
| expect(integration['type']).toBe('aws_proxy') | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.