-
Notifications
You must be signed in to change notification settings - Fork 46
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
tests: Use a random test user when no env vars are present #584
Open
thgreasi
wants to merge
4
commits into
master
Choose a base branch
from
no-env-credentials
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c8d7f6d
tests: Create random test user when no env vars are present
thgreasi 3eb6193
chore: Drop travis tests
thgreasi 8c2ffc5
chore: Run paid user tests on appveyor
thgreasi 0c0240a
chore: Add headless Chrome parameters to work on ResinCi
thgreasi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,10 +15,9 @@ matrix: | |
environment: | ||
matrix: | ||
- nodejs_version: 6 | ||
RESINTEST_EMAIL: '[email protected]' | ||
RESINTEST_USERNAME: 'test3_juan' | ||
RESINTEST_REGISTER_EMAIL: '[email protected]' | ||
RESINTEST_REGISTER_USERNAME: 'test3_register_juan' | ||
RESINTEST_PAID_EMAIL: '[email protected]' | ||
RESINTEST_PAID_PASSWORD: | ||
secure: zqKu7kmQ2b53eRh4lPwKW1ht/Va/ykIuDwdkkT5cwgc= | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version x64 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ _ = require('lodash') | |
chai.use(require('chai-samsam')) | ||
|
||
exports.IS_BROWSER = IS_BROWSER = window? | ||
exports.credentials = {} | ||
|
||
if IS_BROWSER | ||
require('js-polyfills/es6') | ||
|
@@ -30,38 +31,50 @@ _.assign opts, | |
isBrowser: IS_BROWSER, | ||
retries: 3 | ||
|
||
buildCredentials = -> | ||
if not env | ||
throw new Error('Missing environment object?!') | ||
exports.getSdk = getSdk | ||
exports.sdkOpts = opts | ||
exports.resin = resin = getSdk(opts) | ||
|
||
shouldDeleteTestUser = false | ||
|
||
credentials = | ||
email: env.RESINTEST_EMAIL | ||
password: env.RESINTEST_PASSWORD | ||
username: env.RESINTEST_USERNAME | ||
getCredentials = _.once Promise.method -> | ||
username = "sdk_tests_#{Date.now()}" | ||
register_username = "#{username}_reg" | ||
|
||
getUserCredentials = (username) -> | ||
username: username | ||
email: "#{username}@resin.io" | ||
password: "#{username}_!@#" | ||
|
||
tmpEnv = env || {} | ||
envTestUserCredentials = | ||
username: tmpEnv.RESINTEST_USERNAME | ||
email: tmpEnv.RESINTEST_EMAIL | ||
password: tmpEnv.RESINTEST_PASSWORD | ||
|
||
envPaidUserCredentials = | ||
paid: | ||
email: env.RESINTEST_PAID_EMAIL | ||
password: env.RESINTEST_PAID_PASSWORD | ||
register: | ||
email: env.RESINTEST_REGISTER_EMAIL | ||
password: env.RESINTEST_REGISTER_PASSWORD | ||
username: env.RESINTEST_REGISTER_USERNAME | ||
|
||
if not _.every [ | ||
credentials.email? | ||
credentials.password? | ||
credentials.username? | ||
credentials.register.email? | ||
credentials.register.password? | ||
credentials.register.username? | ||
] | ||
throw new Error('Missing environment credentials') | ||
|
||
return credentials | ||
email: tmpEnv.RESINTEST_PAID_EMAIL | ||
password: tmpEnv.RESINTEST_PAID_PASSWORD | ||
|
||
exports.getSdk = getSdk | ||
credentials = _.assign({}, | ||
getUserCredentials(username), | ||
envPaidUserCredentials, | ||
register: getUserCredentials(register_username) | ||
) | ||
|
||
exports.sdkOpts = opts | ||
exports.resin = resin = getSdk(opts) | ||
if _.every(envTestUserCredentials) | ||
console.log('Using ENV test user credentials') | ||
_.assign(credentials, envTestUserCredentials) | ||
return credentials | ||
|
||
resin.auth.register | ||
email: credentials.email | ||
password: credentials.password | ||
.tap -> shouldDeleteTestUser = true | ||
.return(credentials) | ||
.tapCatch -> | ||
console.error('Failed to autogenerate test credentials!') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this should just throw an error here? |
||
|
||
exports.resetUser = -> | ||
return resin.auth.isLoggedIn().then (isLoggedIn) -> | ||
|
@@ -82,8 +95,6 @@ exports.resetUser = -> | |
.catchReturn() | ||
] | ||
|
||
exports.credentials = buildCredentials() | ||
|
||
exports.givenLoggedInUserWithApiKey = -> | ||
beforeEach -> | ||
resin.auth.login | ||
|
@@ -325,3 +336,31 @@ exports.givenMulticontainerApplication = -> | |
@oldWebInstall = oldWebInstall | ||
@newWebInstall = newWebInstall | ||
@newDbInstall = newDbInstall | ||
|
||
before -> | ||
console.log('************ setup ************') | ||
console.log("API Url: #{opts.apiUrl}") | ||
getCredentials() | ||
.then (result) -> | ||
# use assign, since this runs asynchronously, after | ||
# each test has imported the credentials object | ||
_.assign(exports.credentials, result) | ||
.finally -> console.log() | ||
|
||
after -> | ||
console.log('********** teardown **********') | ||
if !shouldDeleteTestUser | ||
return | ||
|
||
resin.auth.login | ||
email: exports.credentials.email | ||
password: exports.credentials.password | ||
.then(resin.auth.getUserId) | ||
.then (userId) -> | ||
return resin.request.send | ||
method: 'DELETE' | ||
url: "/v2/user(#{userId})" | ||
baseUrl: exports.sdkOpts.apiUrl | ||
.then -> console.log('Deleted autogenerated test user') | ||
.then(resin.auth.logout) | ||
.catch(message: 'Request error: Unauthorized', ->) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT:
suit
->suite
extend
->extent