|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'stage domain name' do |
| 6 | + let(:component) { vars(:stage).component } |
| 7 | + let(:deployment_identifier) { vars(:stage).deployment_identifier } |
| 8 | + |
| 9 | + let(:stage_name) { vars(:stage).name } |
| 10 | + |
| 11 | + let(:api_id) do |
| 12 | + output(:prerequisites, 'api_id') |
| 13 | + end |
| 14 | + |
| 15 | + let(:output_stage_id) do |
| 16 | + output(:stage, 'stage_id') |
| 17 | + end |
| 18 | + |
| 19 | + let(:output_access_logging_log_group_arn) do |
| 20 | + output(:stage, 'access_logging_log_group_arn') |
| 21 | + end |
| 22 | + |
| 23 | + let(:output_access_logging_log_group_name) do |
| 24 | + output(:stage, 'access_logging_log_group_name') |
| 25 | + end |
| 26 | + |
| 27 | + let(:api_gateway_stages) do |
| 28 | + api_gateway_v2_client.get_stages(api_id:).items |
| 29 | + end |
| 30 | + |
| 31 | + let(:api_gateway_stage) do |
| 32 | + api_gateway_stages[0] |
| 33 | + end |
| 34 | + |
| 35 | + before(:context) do |
| 36 | + provision(:stage) do |vars| |
| 37 | + vars.merge( |
| 38 | + api_id: output(:prerequisites, 'api_id'), |
| 39 | + include_domain_name: false |
| 40 | + ) |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + after(:context) do |
| 45 | + destroy(:stage) do |vars| |
| 46 | + vars.merge( |
| 47 | + api_id: output(:prerequisites, 'api_id'), |
| 48 | + include_domain_name: false |
| 49 | + ) |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + describe 'by default' do |
| 54 | + it 'enables access logging' do |
| 55 | + expect(api_gateway_stage.access_log_settings).not_to(be_nil) |
| 56 | + end |
| 57 | + |
| 58 | + it 'creates a log group for the access logs' do |
| 59 | + expect(cloudwatch_logs(output_access_logging_log_group_name)).to(exist) |
| 60 | + end |
| 61 | + |
| 62 | + it 'includes the component in the log group name' do |
| 63 | + expect(output_access_logging_log_group_name) |
| 64 | + .to(match(/.*#{component}.*/)) |
| 65 | + end |
| 66 | + |
| 67 | + it 'includes the deployment identifier in the log group name' do |
| 68 | + expect(output_access_logging_log_group_name) |
| 69 | + .to(match(/.*#{deployment_identifier}.*/)) |
| 70 | + end |
| 71 | + |
| 72 | + it 'includes the stage name in the log group name' do |
| 73 | + expect(output_access_logging_log_group_name) |
| 74 | + .to(match(/.*#{stage_name}.*/)) |
| 75 | + end |
| 76 | + |
| 77 | + it 'uses the created log group to store access logs' do |
| 78 | + expect(api_gateway_stage.access_log_settings.destination_arn) |
| 79 | + .to(eq(output_access_logging_log_group_arn)) |
| 80 | + end |
| 81 | + |
| 82 | + # rubocop:disable RSpec/ExampleLength |
| 83 | + it 'logs everything' do |
| 84 | + expect(api_gateway_stage.access_log_settings.format) |
| 85 | + .to(eq( |
| 86 | + '{' \ |
| 87 | + '"accountId": "$context.accountId", ' \ |
| 88 | + '"apiId": "$context.apiId", ' \ |
| 89 | + '"authorizer.claims.property": ' \ |
| 90 | + '"$context.authorizer.claims.property", ' \ |
| 91 | + '"authorizer.error": "$context.authorizer.error", ' \ |
| 92 | + '"authorizer.principalId": ' \ |
| 93 | + '"$context.authorizer.principalId", ' \ |
| 94 | + '"authorizer.property": "$context.authorizer.property", ' \ |
| 95 | + '"awsEndpointRequestId": ' \ |
| 96 | + '"$context.awsEndpointRequestId", ' \ |
| 97 | + '"awsEndpointRequestId2": ' \ |
| 98 | + '"$context.awsEndpointRequestId2", ' \ |
| 99 | + '"customDomain.basePathMatched": ' \ |
| 100 | + '"$context.customDomain.basePathMatched", ' \ |
| 101 | + '"dataProcessed": $context.dataProcessed, ' \ |
| 102 | + '"domainName": "$context.domainName", ' \ |
| 103 | + '"domainPrefix": "$context.domainPrefix", ' \ |
| 104 | + '"error.message": "$context.error.message", ' \ |
| 105 | + '"error.messageString": "$context.error.messageString", ' \ |
| 106 | + '"error.responseType": "$context.error.responseType", ' \ |
| 107 | + '"extendedRequestId": "$context.extendedRequestId", ' \ |
| 108 | + '"httpMethod": "$context.httpMethod", ' \ |
| 109 | + '"identity.accountId": "$context.identity.accountId", ' \ |
| 110 | + '"identity.caller": "$context.identity.caller", ' \ |
| 111 | + '"identity.cognitoAuthenticationProvider": ' \ |
| 112 | + '"$context.identity.cognitoAuthenticationProvider", ' \ |
| 113 | + '"identity.cognitoAuthenticationType": ' \ |
| 114 | + '"$context.identity.cognitoAuthenticationType", ' \ |
| 115 | + '"identity.cognitoIdentityId": ' \ |
| 116 | + '"$context.identity.cognitoIdentityId", ' \ |
| 117 | + '"identity.cognitoIdentityPoolId": ' \ |
| 118 | + '"$context.identity.cognitoIdentityPoolId", ' \ |
| 119 | + '"identity.principalOrgId": ' \ |
| 120 | + '"$context.identity.principalOrgId", ' \ |
| 121 | + '"identity.clientCert.clientCertPem": ' \ |
| 122 | + '"$context.identity.clientCert.clientCertPem", ' \ |
| 123 | + '"identity.clientCert.subjectDN": ' \ |
| 124 | + '"$context.identity.clientCert.subjectDN", ' \ |
| 125 | + '"identity.clientCert.issuerDN": ' \ |
| 126 | + '"$context.identity.clientCert.issuerDN", ' \ |
| 127 | + '"identity.clientCert.serialNumber": ' \ |
| 128 | + '"$context.identity.clientCert.serialNumber", ' \ |
| 129 | + '"identity.clientCert.validity.notBefore": ' \ |
| 130 | + '"$context.identity.clientCert.validity.notBefore", ' \ |
| 131 | + '"identity.clientCert.validity.notAfter": ' \ |
| 132 | + '"$context.identity.clientCert.validity.notAfter", ' \ |
| 133 | + '"identity.sourceIp": "$context.identity.sourceIp", ' \ |
| 134 | + '"identity.user": "$context.identity.user", ' \ |
| 135 | + '"identity.userAgent": "$context.identity.userAgent", ' \ |
| 136 | + '"identity.userArn": "$context.identity.userArn", ' \ |
| 137 | + '"integration.error": "$context.integration.error", ' \ |
| 138 | + '"integration.integrationStatus": ' \ |
| 139 | + '$context.integration.integrationStatus, ' \ |
| 140 | + '"integration.latency": $context.integration.latency, ' \ |
| 141 | + '"integration.requestId": ' \ |
| 142 | + '"$context.integration.requestId", ' \ |
| 143 | + '"integration.status": $context.integration.status, ' \ |
| 144 | + '"integrationErrorMessage": ' \ |
| 145 | + '"$context.integrationErrorMessage", ' \ |
| 146 | + '"integrationLatency": $context.integrationLatency, ' \ |
| 147 | + '"integrationStatus": $context.integrationStatus, ' \ |
| 148 | + '"path": "$context.path", ' \ |
| 149 | + '"protocol": "$context.protocol", ' \ |
| 150 | + '"requestId": "$context.requestId", ' \ |
| 151 | + '"requestTime": "$context.requestTime", ' \ |
| 152 | + '"requestTimeEpoch": "$context.requestTimeEpoch", ' \ |
| 153 | + '"responseLatency": $context.responseLatency, ' \ |
| 154 | + '"responseLength": $context.responseLength, ' \ |
| 155 | + '"routeKey": "$context.routeKey", ' \ |
| 156 | + '"stage": "$context.stage", ' \ |
| 157 | + '"status": $context.status' \ |
| 158 | + '}' |
| 159 | + )) |
| 160 | + end |
| 161 | + # rubocop:enable RSpec/ExampleLength |
| 162 | + end |
| 163 | +end |
0 commit comments