Skip to content
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

test(client-s3): add cross platform integration test #1296

Merged
merged 11 commits into from
Jun 30, 2020

Conversation

AllanZhengYP
Copy link
Contributor

@AllanZhengYP AllanZhengYP commented Jun 25, 2020

This is an sample to add cross-platform integration test to a client.

The package @aws-sdk/karma-credential-loader is a preprocessor used by karma browser integration test. But it does is that it will call the Node.js-specific region and credential provider to load value from the environment. Then define these varibles(defaultRegion, credentials, isBrowsers) in the bundled artifact generated by karma.

Under S3 client folder, users can run the bellow command to run the same integration test suite in Node.js, chrome, and Firefox.

AWS_SMOKE_TEST_REGION=us-west-2 yarn test:e2e

All the integration tests must have extensionXX.ispec.ts. The test suites should have defaultRegion, credentials, isBrowsers vaiables defined in browser tests. In Node.js test, these parameters need to be initialized before using. Because Node.js client itself can load credentials and region from the environment, the test can just initialize them to undefined.

Console output

yarn run v1.17.3
$ mocha **/cjs/**/*.ispec.js && karma start karma.conf.js


  1 passing (2ms)

ℹ 「wdm」: Compiled successfully.
ℹ 「wdm」: Compiling...
ℹ 「wdm」:    279 modules
ℹ 「wdm」: Compiled successfully.
Chrome Headless 83.0.4103.116 (Mac OS 10.13.6): Executed 1 of 1 SUCCESS (0.299 secs / 0.213 secs)
Firefox 68.0 (Mac OS 10.13): Executed 1 of 1 SUCCESS (0.544 secs / 0.455 secs)
TOTAL: 2 SUCCESS
✨  Done in 33.16s.

CodeBuild validation on commit aa4977c: login and review the console

To run the S3 integ test, the user need to:

  • Have permissiont to the testing bucket(hardcoded as aws-sdk-unit-test).
  • The testing bucket should be CORS enabled
  • The test environment should have firefox installed(AWS CodeBuild standard image comes with it).

TODO:

  • adding more S3 tests(ListObjects(), PutObject(), CreateMultipartUpload(), UploadPart(), CompleteMultipartUpload(), ListParts(), AbortMultipart())
  • In separate PR, add more Cogenito-Idenity test(GetId(), GetCredentialsForIdentity())

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2020

Codecov Report

Merging #1296 into master will increase coverage by 4.31%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1296      +/-   ##
==========================================
+ Coverage   73.17%   77.49%   +4.31%     
==========================================
  Files         290      286       -4     
  Lines       12792    11899     -893     
  Branches     2936     2600     -336     
==========================================
- Hits         9361     9221     -140     
+ Misses       3431     2678     -753     
Impacted Files Coverage Δ
clients/client-s3/runtimeConfig.ts
clients/client-s3/S3.ts
clients/client-s3/S3Client.ts
clients/client-s3/runtimeConfig.shared.ts

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bddeb3d...12d4090. Read the comment docs.

@alexforsyth alexforsyth self-requested a review June 25, 2020 17:13
@AllanZhengYP AllanZhengYP marked this pull request as ready for review June 29, 2020 17:04
Copy link
Member

@trivikr trivikr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting AccessDenied errors when trying to run locally.

console output
$ pwd
/home/trivikr/workspace/aws-sdk-js-v3/clients/client-s3

$ AWS_SMOKE_TEST_REGION=us-west-2 yarn test:e2e                 
yarn run v1.22.4
$ mocha **/cjs/**/*.ispec.js && karma start karma.conf.js


  @aws-sdk/client-s3
    PutObject
      1) should succeed with Node.js readable stream body
      2) "after all" hook for "should succeed with Node.js readable stream body"
    ListObjects
      3) should succeed with valid bucket
      ✓ should throw with invalid bucket
    MultipartUpload
      4) should successfully create, upload list and complete
      5) "after each" hook for "should successfully create, upload list and complete"


  1 passing (106ms)
  5 failing

  1) @aws-sdk/client-s3
       PutObject
         should succeed with Node.js readable stream body:
     AccessDenied: Access Denied
      at deserializeAws_restXmlPutObjectCommandError (dist/cjs/protocols/Aws_restXml.js:6368:41)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  2) @aws-sdk/client-s3
       PutObject
         "after all" hook for "should succeed with Node.js readable stream body":
     AccessDenied: Access Denied
      at deserializeAws_restXmlDeleteObjectCommandError (dist/cjs/protocols/Aws_restXml.js:4000:41)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  3) @aws-sdk/client-s3
       ListObjects
         should succeed with valid bucket:
     AccessDenied: Access Denied
      at deserializeAws_restXmlListObjectsCommandError (dist/cjs/protocols/Aws_restXml.js:5623:41)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  4) @aws-sdk/client-s3
       MultipartUpload
         should successfully create, upload list and complete:
     AccessDenied: Access Denied
      at deserializeAws_restXmlCreateMultipartUploadCommandError (dist/cjs/protocols/Aws_restXml.js:3675:41)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)

  5) @aws-sdk/client-s3
       MultipartUpload
         "after each" hook for "should successfully create, upload list and complete":
     AccessDenied: Access Denied
      at deserializeAws_restXmlDeleteObjectCommandError (dist/cjs/protocols/Aws_restXml.js:4000:41)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)



error Command failed with exit code 5.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Verified that integrations tests are working with my default profile

console output
$ pwd
/home/trivikr/workspace/aws-sdk-js-v3

$ yarn test:integration-legacy --tags @acm
yarn run v1.22.4
$ cucumber-js --fail-fast --tags @acm
.........

2 scenarios (2 passed)
5 steps (5 passed)
0m00.138s
Done in 2.52s.

clients/client-s3/e2e/S3.ispec.ts Outdated Show resolved Hide resolved
clients/client-s3/e2e/S3.ispec.ts Outdated Show resolved Hide resolved
clients/client-s3/e2e/S3.ispec.ts Outdated Show resolved Hide resolved
clients/client-s3/e2e/S3.ispec.ts Outdated Show resolved Hide resolved
@AllanZhengYP
Copy link
Contributor Author

AllanZhengYP commented Jun 30, 2020

@trivikr Sorry for not being clear on resources needed for the testing evironment. As mentioned here, this smoke test requires an existing bucket:

// this bucket requires enabling CORS:
// AllowedOrigin(), AllowedMethod(GET, PUT, POST, DELETE, HEAD), ExposeHeader(ETag), AllowedHeader()

This is required because programmably CreateBucket is not allowed in browsers because of CORS. Although we can test it for Node and potentially Chrome(they provide an easy way to turn off CORS in testing), but Firefox doesn't allow it.

This is a quirk of S3, most other serivices don't have this problem, they simply support or not support CORS for all the operations. But S3 just doesn't support CORS for only the bucket operations.

Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants