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

Reprovision Storage Integration test backend #256

Merged
merged 7 commits into from
Dec 18, 2019

Conversation

lawmicha
Copy link
Contributor

@lawmicha lawmicha commented Dec 12, 2019

Major changes

  • reprovisioned storage resource in test account
  • Adding readme for integration test set up

Minor changes

  • Moved AuthHelper to AmplifyTestCommon for API and Storage tests

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lawmicha lawmicha requested review from palpatim and wooj2 December 12, 2019 16:49
@lawmicha lawmicha changed the title - reprovisioned storage resource in test account Reprovision Storage Integration tests Dec 12, 2019
@lawmicha lawmicha self-assigned this Dec 12, 2019
@lawmicha lawmicha added the storage Issues related to the Storage category label Dec 12, 2019
@lawmicha lawmicha changed the title Reprovision Storage Integration tests Reprovision Storage Integration test backend Dec 12, 2019
Copy link
Member

@palpatim palpatim left a comment

Choose a reason for hiding this comment

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

Need to move the password out of the file unless it is our intention to provision a new user pool/storage backend and tear it down after each integ test run.

@@ -19,8 +20,8 @@ class AWSS3StoragePluginAccessLevelTests: AWSS3StoragePluginTestBase {

// This is a run once function to set up users then use console to verify and run rest of these tests.
func testSetUpOnce() {
signUpUser(username: user1)
signUpUser(username: user2)
AuthHelper.signUpUser(username: user1, password: password)
Copy link
Member

Choose a reason for hiding this comment

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

We need to move the password out of the source file and into a setup run from the CLI. As it stands, if an attacker obtains our user pool ID (which remember is not considered sensitive), they could use the test storage bucket to store and distribute files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

depending on what the attacker obtains, couldn't they also just create their own user as well? I thought that if awsconfiguration.json and amplifyconfiguration.json is never exposed then we are good, and the username and password for this user is specific for the user pool and wouldn't provide any value to the attacker.

if we need to move this out, i can follow a similar pattern and have another file like credentials.json that gets pulled down like https://github.com/aws-amplify/aws-sdk-ios/blob/f3967e2e2a648e8a114ef5dd50bef5e075668693/AWSAuthSDK/AWSAuthSDKTestAppUITests/AWSDropInUIUserPoolTests.swift#L24

Copy link
Member

@palpatim palpatim Dec 17, 2019

Choose a reason for hiding this comment

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

We treat things like pool IDs with different sensitivity than credentials like password. (e.g., we may log a user pool ID). A credentials.json pattern or similar would be one way to protect that, but let's talk about it IRL to make sure we don't end up with a catch-all for "everything that doesn't fit in a config file." :)

If this test is setting up something that allows guest access, we need to have some controls in place to ensure we don't have unauthorized access to our bucket. Again, let's discuss IRL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

discussed with tim and in the current state of things, we'll do a couple of things to make things more secure and less prone to abuse:

  1. credentials.json to contain user/pass. this can be stored in the same pattern as the configuration files, ie. AWSS3StorageIntegrationTests-credentials.json.
  2. Not as urgent for API plugin but will do the same
  3. add *credentials.json to .gitignore
  4. bucket policy updated to expire asap, looks like 1 day is the shortest possible.
  5. The tests need to be prone to parallel execution. S3 keys defined in the tests should contain some unique identifier. there are many cases where the tests may be run in parallel. Multiple circleCI runs and developer using test account locally (though ideally developer should create their own resources using the readme instructions).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ExpireObjectsRule

@@ -13,8 +13,8 @@ class AuthHelper {
let callbackInvoked = DispatchSemaphore(value: 0)

AWSMobileClient.default().initialize { userState, error in
if let error = error {
fatalError("Error initializing AWSMobileClient. Error: \(error.localizedDescription)")
if let error = error as? AWSMobileClientError {
Copy link
Member

Choose a reason for hiding this comment

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

Why only fatal on AWSMobileClientErrors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i didn't think AWSMobileClient returns anything other than AWSMobileClientErrors, so i was casting to it and extracting the message out for a friendly local debugging message

Copy link
Member

Choose a reason for hiding this comment

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

I follow your logic, but it relies a lot of knowledge of the code paths that lead up to this, which in AWSMobileClient is a little fraught right now. Consider a pattern that logs the message if it's an AWSMobielClientError and the localizedDescription otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adding check for AWSMobileClientError, else fatalError with localizedDescription

@lawmicha lawmicha force-pushed the lawmicha/has-syncable-flag branch 2 times, most recently from fcc497a to f3b683c Compare December 16, 2019 17:19
- Moved AuthHelper to AmplifyTestCommon for API and Storage tests
- Adding readme for integration test set up
@lawmicha lawmicha force-pushed the lawmicha/storage-reprovision branch from 7fe0c7d to 2ea82d4 Compare December 16, 2019 20:32
@lawmicha lawmicha changed the base branch from lawmicha/has-syncable-flag to master December 16, 2019 20:32
- Storage tests use unique UUIDs as keys to allow parallel execution
- updated README with credentials.json structure
- Added for API's GraphQLWithUserPool tests as well
@lawmicha lawmicha requested a review from palpatim December 17, 2019 18:05
Copy link
Member

@palpatim palpatim left a comment

Choose a reason for hiding this comment

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

Some small changes but otherwise LGTM

let credentials = try TestConfigHelper.retrieveCredentials(
forResource: GraphQLWithUserPoolIntegrationTests.credentials)

if credentials["user1"] == nil || credentials["password"] == nil {
Copy link
Member

Choose a reason for hiding this comment

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

nit: prefer guard let when you're trying to get actual values:

guard let userName = credentials["user1"], let password = credentials["password"] else {...}

@@ -42,18 +56,19 @@ class GraphQLWithUserPoolIntegrationTests: XCTestCase {
Amplify.reset()
}

let user1 = "[email protected]"
let password = "Abc123@@!!"

// This is a run once function to set up users then use console to verify and run rest of these tests.
func testSetUpOnce() {
Copy link
Member

Choose a reason for hiding this comment

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

Since running this by itself isn't sufficient to actually provision the test user, let's remove it altogether in favor of including CLI commands or console instructions in the test setup README.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updating readme with instructions on setting up a user and removing disabled method


override func setUp() {
do {

let credentials = try TestConfigHelper.retrieveCredentials(
Copy link
Member

Choose a reason for hiding this comment

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

Put this into the static setUp since you only have to read the credentials file once

override func setUp() {
do {

let credentials = try TestConfigHelper.retrieveCredentials(forResource: AWSS3StoragePluginTestBase.credentials)
Copy link
Member

Choose a reason for hiding this comment

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

make this a static set up method?

@lawmicha lawmicha merged commit 89fd3a6 into master Dec 18, 2019
@palpatim palpatim deleted the lawmicha/storage-reprovision branch December 24, 2019 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
storage Issues related to the Storage category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants