Add 2FA test and 2FA support for integration tests #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Credentials for non 2FA/MFA-enabled accounts as well as 2FA/MFA-enabled accounts are supplied from the environment.
For tests that can use both types of credentials, credentials for non 2FA/MFA-enabled accounts are preferred, if available.
Tests that require one or the other type of credentials/accounts are skipped if the required type of credentials is not available.
A new test-only dependency is introduced for generating 2FA/MFA codes from their secrets:
github.com/pquerna/[email protected]
.golang.org/x/crypto
has been bumped to the latest version.This is not ready because I cannot get the tests to pass properly.
With a 2FA/MFA-enabled account, I can get all tests to pass except one if I:
When these workarounds are not all performed, the tests will fail with the following error:
The upload target URL you are trying to access has expired. Please request a fresh one
.Additionally,
TestEventNotify
is not passing no matter what, with the same error.I have not tested with a non 2FA/MFA-enabled account.
Currently my knowledge of MEGA's API and SDK internals is limited, so any help fixing these issues is appreciated.
I would expect we need to at least clean up sessions between tests (perform a logout).
Test setup to replicate the above results (for a 2FA/MFA-enabled account:
Export these variables to the environment:
Run tests.
Note that you may need to increase
go test
's-timeout
if the MEGA account user for testing has many files, because for such accounts it may take a long time to login.This also explains the decision to pass the 2FA/MFA secret and calculate the codes just-in-time for each test instead of passing in a code for all tests.
With a large account, some tests can take more than 30s to run, causing the remaining tests to be skipped due to any single code becoming invalid in the meantime.