Skip to content

Commit 8099119

Browse files
committed
CCM-14325: Remove authentication from PDM mock
1 parent 33c3e94 commit 8099119

12 files changed

Lines changed: 7 additions & 216 deletions

File tree

infrastructure/terraform/components/dl/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ No requirements.
4040
| <a name="input_mesh_poll_schedule"></a> [mesh\_poll\_schedule](#input\_mesh\_poll\_schedule) | Schedule to poll MESH for messages | `string` | `"rate(5 minutes)"` | no |
4141
| <a name="input_metadata_refresh_schedule"></a> [metadata\_refresh\_schedule](#input\_metadata\_refresh\_schedule) | Schedule for refreshing reporting metadata. | `string` | `"cron(10 6-22 * * ? *)"` | no |
4242
| <a name="input_parent_acct_environment"></a> [parent\_acct\_environment](#input\_parent\_acct\_environment) | Name of the environment responsible for the acct resources used, affects things like DNS zone. Useful for named dev environments | `string` | `"main"` | no |
43-
| <a name="input_pdm_mock_access_token"></a> [pdm\_mock\_access\_token](#input\_pdm\_mock\_access\_token) | Mock access token for PDM API authentication (used in local/dev environments) | `string` | `"mock-pdm-token"` | no |
44-
| <a name="input_pdm_use_non_mock_token"></a> [pdm\_use\_non\_mock\_token](#input\_pdm\_use\_non\_mock\_token) | Whether to use the shared APIM access token from SSM (/component/environment/apim/access\_token) instead of the mock token | `bool` | `false` | no |
4543
| <a name="input_pii_data_retention_policy_days"></a> [pii\_data\_retention\_policy\_days](#input\_pii\_data\_retention\_policy\_days) | The number of days for data retention policy for PII | `number` | `534` | no |
4644
| <a name="input_project"></a> [project](#input\_project) | The name of the tfscaffold project | `string` | n/a | yes |
4745
| <a name="input_queue_batch_size"></a> [queue\_batch\_size](#input\_queue\_batch\_size) | maximum number of queue items to process | `number` | `10` | no |

infrastructure/terraform/components/dl/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ locals {
44
apim_keystore_s3_bucket = "nhs-${var.aws_account_id}-${var.region}-${var.environment}-${var.component}-static-assets"
55
apim_private_key_ssm_parameter_name = "/${var.component}/${var.environment}/apim/private_key"
66
aws_lambda_functions_dir_path = "../../../../lambdas"
7+
pdm_access_token_ssm_parameter_name = var.enable_pdm_mock ? "" : "${local.apim_access_token_ssm_parameter_name}"
78
pdm_url = var.enable_pdm_mock ? aws_api_gateway_stage.pdm_mock[0].invoke_url : var.apim_base_url
89
firehose_output_path_prefix = "kinesis-firehose-output"
910
log_destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"

infrastructure/terraform/components/dl/module_lambda_pdm_poll.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module "pdm_poll" {
3636

3737
lambda_env_vars = {
3838
"APIM_BASE_URL" = local.pdm_url
39-
"APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.apim_access_token_ssm_parameter_name
39+
"APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.pdm_access_token_ssm_parameter_name
4040
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
4141
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
4242
"POLL_MAX_RETRIES" = 10

infrastructure/terraform/components/dl/module_lambda_pdm_uploader.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module "pdm_uploader" {
3636

3737
lambda_env_vars = {
3838
"APIM_BASE_URL" = local.pdm_url
39-
"APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.apim_access_token_ssm_parameter_name
39+
"APIM_ACCESS_TOKEN_SSM_PARAMETER_NAME" = local.pdm_access_token_ssm_parameter_name
4040
"EVENT_PUBLISHER_EVENT_BUS_ARN" = aws_cloudwatch_event_bus.main.arn
4141
"EVENT_PUBLISHER_DLQ_URL" = module.sqs_event_publisher_errors.sqs_queue_url
4242
}

infrastructure/terraform/components/dl/ssm_parameter_access_token.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ resource "aws_ssm_parameter" "access_token" {
22
name = local.apim_access_token_ssm_parameter_name
33
description = "Access token for APIM"
44
type = "SecureString"
5-
value = jsonencode({
6-
tokens = []
7-
})
5+
value = jsonencode({})
6+
87
tags = merge(local.default_tags, { Backup = "true" })
98

109
lifecycle {

infrastructure/terraform/components/dl/variables.tf

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,6 @@ variable "ttl_poll_schedule" {
122122
default = "rate(10 minutes)" # Every 10 minutes
123123
}
124124

125-
variable "pdm_mock_access_token" {
126-
type = string
127-
description = "Mock access token for PDM API authentication (used in local/dev environments)"
128-
default = "mock-pdm-token"
129-
}
130-
131-
variable "pdm_use_non_mock_token" {
132-
type = bool
133-
description = "Whether to use the shared APIM access token from SSM (/component/environment/apim/access_token) instead of the mock token"
134-
default = false
135-
}
136-
137125
variable "apim_base_url" {
138126
type = string
139127
description = "The URL used to send requests to PDM"

lambdas/pdm-mock-lambda/src/__tests__/authenticator.test.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

lambdas/pdm-mock-lambda/src/__tests__/container.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@ describe('Container', () => {
3535

3636
it('should create a container with all required dependencies', () => {
3737
expect(container).toBeDefined();
38-
expect(container.authenticator).toBeDefined();
3938
expect(container.getResourceHandler).toBeDefined();
4039
expect(container.createResourceHandler).toBeDefined();
4140
expect(container.logger).toBeDefined();
4241
});
4342

44-
it('should create an authenticator function', () => {
45-
expect(typeof container.authenticator).toBe('function');
46-
});
47-
4843
it('should create a getResourceHandler function', () => {
4944
expect(typeof container.getResourceHandler).toBe('function');
5045
});
@@ -74,14 +69,4 @@ describe('Container', () => {
7469
expect(result).toBeDefined();
7570
expect(result.statusCode).toBeDefined();
7671
});
77-
78-
it('should create authenticator that can be called', async () => {
79-
const mockEvent = {
80-
headers: { Authorization: 'Bearer test-token' },
81-
};
82-
83-
const result = await container.authenticator(mockEvent);
84-
expect(result).toBeDefined();
85-
expect(result.isValid).toBeDefined();
86-
});
8772
});

lambdas/pdm-mock-lambda/src/__tests__/index.test.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -66,41 +66,18 @@ const createMockEvent = (
6666
};
6767

6868
describe('Lambda Handler Integration', () => {
69-
let mockAuthenticator: jest.Mock;
7069
let mockGetResourceHandler: jest.Mock;
7170
let mockCreateResourceHandler: jest.Mock;
7271

7372
beforeEach(() => {
7473
jest.clearAllMocks();
7574

7675
const container = createContainer();
77-
mockAuthenticator = container.authenticator as jest.Mock;
7876
mockGetResourceHandler = container.getResourceHandler as jest.Mock;
7977
mockCreateResourceHandler = container.createResourceHandler as jest.Mock;
8078
});
8179

82-
it('should return authentication error when authentication fails', async () => {
83-
mockAuthenticator.mockResolvedValue({
84-
isValid: false,
85-
error: {
86-
statusCode: 401,
87-
body: JSON.stringify({ error: 'Unauthorized' }),
88-
},
89-
});
90-
91-
const event = createMockEvent();
92-
const response = (await handler(
93-
event,
94-
{} as Context,
95-
{} as Callback,
96-
)) as APIGatewayProxyResult;
97-
98-
expect(response.statusCode).toBe(401);
99-
expect(mockGetResourceHandler).not.toHaveBeenCalled();
100-
});
101-
10280
it('should route GET requests to getResourceHandler', async () => {
103-
mockAuthenticator.mockResolvedValue({ isValid: true });
10481
mockGetResourceHandler.mockResolvedValue({
10582
statusCode: 200,
10683
body: JSON.stringify({ id: 'test-id' }),
@@ -117,13 +94,11 @@ describe('Lambda Handler Integration', () => {
11794
{} as Callback,
11895
)) as APIGatewayProxyResult;
11996

120-
expect(mockAuthenticator).toHaveBeenCalledWith(event);
12197
expect(mockGetResourceHandler).toHaveBeenCalledWith(event);
12298
expect(response.statusCode).toBe(200);
12399
});
124100

125101
it('should route POST requests to createResourceHandler', async () => {
126-
mockAuthenticator.mockResolvedValue({ isValid: true });
127102
mockCreateResourceHandler.mockResolvedValue({
128103
statusCode: 201,
129104
body: JSON.stringify({ id: 'new-id' }),
@@ -141,14 +116,11 @@ describe('Lambda Handler Integration', () => {
141116
{} as Callback,
142117
)) as APIGatewayProxyResult;
143118

144-
expect(mockAuthenticator).toHaveBeenCalledWith(event);
145119
expect(mockCreateResourceHandler).toHaveBeenCalledWith(event);
146120
expect(response.statusCode).toBe(201);
147121
});
148122

149123
it('should return 404 for unsupported endpoints', async () => {
150-
mockAuthenticator.mockResolvedValue({ isValid: true });
151-
152124
const event = createMockEvent({
153125
httpMethod: 'DELETE',
154126
path: '/unsupported',
@@ -165,7 +137,7 @@ describe('Lambda Handler Integration', () => {
165137
});
166138

167139
it('should handle unexpected errors gracefully', async () => {
168-
mockAuthenticator.mockRejectedValue(new Error('Unexpected error'));
140+
mockGetResourceHandler.mockRejectedValue(new Error('Unexpected error'));
169141

170142
const event = createMockEvent();
171143
const response = (await handler(

lambdas/pdm-mock-lambda/src/authenticator.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)