|
3 | 3 | * SPDX-License-Identifier: MIT |
4 | 4 | */ |
5 | 5 |
|
6 | | -import { IAM, Lambda } from 'aws-sdk' |
| 6 | +import { AWSError, IAM, Lambda } from 'aws-sdk' |
7 | 7 | import { SdkUtils } from 'lib/sdkutils' |
8 | 8 | import { TaskOperations } from 'tasks/LambdaDeployFunction/TaskOperations' |
9 | 9 | import { deployCodeAndConfig, deployCodeOnly, TaskParameters } from 'tasks/LambdaDeployFunction/TaskParameters' |
@@ -84,6 +84,20 @@ const waitForFails = { |
84 | 84 | } |
85 | 85 | } |
86 | 86 |
|
| 87 | +const waitForPermissionsGetConfigurationFails = { |
| 88 | + promise: function() { |
| 89 | + const e = new Error() as AWSError |
| 90 | + e.code = 'ResourceNotReady' |
| 91 | + e.message = 'Resource is not in the state of denial' |
| 92 | + e.originalError = { |
| 93 | + code: 'AccessDeniedException', |
| 94 | + message: |
| 95 | + 'User: youHaveNoPowerHere is not authorized to perform: lambda:GetFunctionConfiguration on resource: resource with an explicit deny in an identity-based policy' |
| 96 | + } as AWSError |
| 97 | + throw e |
| 98 | + } |
| 99 | +} |
| 100 | + |
87 | 101 | describe('Lambda Deploy Function', () => { |
88 | 102 | // TODO https://github.com/aws/aws-vsts-tools/issues/167 |
89 | 103 | beforeAll(() => { |
@@ -147,6 +161,22 @@ describe('Lambda Deploy Function', () => { |
147 | 161 | expect(lambda.waitFor).toBeCalledTimes(1) |
148 | 162 | }) |
149 | 163 |
|
| 164 | + test('Deploy only Function exists calls wait and still updates if wait fails due to waiter permissions', async () => { |
| 165 | + expect.assertions(3) |
| 166 | + const taskParameters = { ...baseTaskParameters } |
| 167 | + taskParameters.deploymentMode = deployCodeOnly |
| 168 | + taskParameters.roleARN = 'arn:yes' |
| 169 | + const lambda = new Lambda() as any |
| 170 | + lambda.getFunction = jest.fn(() => getFunctionSucceeds) |
| 171 | + lambda.updateFunctionCode = jest.fn(() => updateFunctionSucceeds) |
| 172 | + lambda.waitFor = jest.fn(() => waitForPermissionsGetConfigurationFails) |
| 173 | + const taskOperations = new TaskOperations(new IAM(), lambda, taskParameters, 0) |
| 174 | + await taskOperations.execute() |
| 175 | + expect(lambda.getFunction).toBeCalledTimes(1) |
| 176 | + expect(lambda.updateFunctionCode).toBeCalledTimes(1) |
| 177 | + expect(lambda.waitFor).toBeCalledTimes(1) |
| 178 | + }) |
| 179 | + |
150 | 180 | test('Deploy only Function exists calls update but fails if status does not update', async () => { |
151 | 181 | expect.assertions(4) |
152 | 182 | const taskParameters = { ...baseTaskParameters } |
@@ -179,6 +209,22 @@ describe('Lambda Deploy Function', () => { |
179 | 209 | expect(lambda.waitFor).toBeCalledTimes(1) |
180 | 210 | }) |
181 | 211 |
|
| 212 | + test('Deploy and config does not exist calls create and still updates if wait fails due to waiter permissions', async () => { |
| 213 | + expect.assertions(3) |
| 214 | + const taskParameters = { ...baseTaskParameters } |
| 215 | + taskParameters.deploymentMode = deployCodeAndConfig |
| 216 | + taskParameters.roleARN = 'arn:yes' |
| 217 | + const lambda = new Lambda() as any |
| 218 | + lambda.getFunction = jest.fn(() => getFunctionFails) |
| 219 | + lambda.createFunction = jest.fn(() => updateFunctionSucceeds) |
| 220 | + lambda.waitFor = jest.fn(() => waitForPermissionsGetConfigurationFails) |
| 221 | + const taskOperations = new TaskOperations(new IAM(), lambda, taskParameters, 0) |
| 222 | + await taskOperations.execute() |
| 223 | + expect(lambda.getFunction).toBeCalledTimes(1) |
| 224 | + expect(lambda.createFunction).toBeCalledTimes(1) |
| 225 | + expect(lambda.waitFor).toBeCalledTimes(1) |
| 226 | + }) |
| 227 | + |
182 | 228 | test('Deploy and config does not exist calls create but fails if status does not update', async () => { |
183 | 229 | expect.assertions(4) |
184 | 230 | const taskParameters = { ...baseTaskParameters } |
@@ -213,6 +259,24 @@ describe('Lambda Deploy Function', () => { |
213 | 259 | expect(lambda.waitFor).toBeCalledTimes(2) |
214 | 260 | }) |
215 | 261 |
|
| 262 | + test('Deploy and config exists calls update and still updates if wait fails due to waiter permissions', async () => { |
| 263 | + expect.assertions(4) |
| 264 | + const taskParameters = { ...baseTaskParameters } |
| 265 | + taskParameters.deploymentMode = deployCodeAndConfig |
| 266 | + taskParameters.roleARN = 'arn:yes' |
| 267 | + const lambda = new Lambda() as any |
| 268 | + lambda.getFunction = jest.fn(() => getFunctionSucceeds) |
| 269 | + lambda.updateFunctionCode = jest.fn(() => updateFunctionSucceeds) |
| 270 | + lambda.updateFunctionConfiguration = jest.fn(() => updateFunctionSucceeds) |
| 271 | + lambda.waitFor = jest.fn(() => waitForPermissionsGetConfigurationFails) |
| 272 | + const taskOperations = new TaskOperations(new IAM(), lambda, taskParameters, 0) |
| 273 | + await taskOperations.execute() |
| 274 | + expect(lambda.getFunction).toBeCalledTimes(1) |
| 275 | + expect(lambda.updateFunctionCode).toBeCalledTimes(1) |
| 276 | + expect(lambda.updateFunctionConfiguration).toBeCalledTimes(1) |
| 277 | + expect(lambda.waitFor).toBeCalledTimes(2) |
| 278 | + }) |
| 279 | + |
216 | 280 | test('Deploy and config exists calls update but fails if status does not update after config update', async () => { |
217 | 281 | expect.assertions(5) |
218 | 282 | const taskParameters = { ...baseTaskParameters } |
|
0 commit comments