-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fastboot] Integration testing for fastboot (#1045)
* Add session register back * Create a fastboot test app and create basic tests against fastboot.
- Loading branch information
1 parent
6a341d6
commit 2bd16a7
Showing
29 changed files
with
346 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* global require, process */ | ||
var glob = require('glob'); | ||
var Mocha = require('mocha'); | ||
|
||
var root = 'node-tests/fastboot'; | ||
|
||
var mocha = new Mocha({ | ||
timeout: 5000, | ||
reporter: 'spec' | ||
}); | ||
|
||
var testFiles = glob.sync(root + '/**/*-test.js'); | ||
|
||
addFiles(mocha, testFiles); | ||
|
||
try { | ||
runMocha(); | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
|
||
function addFiles(mocha, files) { | ||
files = (typeof files === 'string') ? glob.sync(root + files) : files; | ||
files.forEach(mocha.addFile.bind(mocha)); | ||
} | ||
|
||
function runMocha() { | ||
mocha.run(function(failures) { | ||
process.on('exit', function() { | ||
process.exit(failures); | ||
}); | ||
}); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* global describe, before, after, it */ | ||
/* jshint node:true */ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
var RSVP = require('rsvp'); | ||
var AddonTestApp = require('ember-cli-addon-tests').AddonTestApp; | ||
var request = require('request'); | ||
var request = RSVP.denodeify(request); | ||
|
||
describe('Basic tests', function() { | ||
this.timeout(600000); | ||
|
||
var app; | ||
var url = 'http://localhost:49741'; | ||
|
||
before(function() { | ||
app = new AddonTestApp(); | ||
return app.create('fastboot-app', { fixturesPath: 'node-tests/fixtures/' }) | ||
.then(addDependencies) | ||
.then(function() { | ||
return app.startServer({ | ||
command: 'fastboot', | ||
additionalArguments: ['--host 0.0.0.0'] | ||
}); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
return app.stopServer(); | ||
}); | ||
|
||
it('redirects to login page on a protected route', function() { | ||
return request({ url: url + '/protected' }) | ||
.then(function(response) { | ||
|
||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D; path=/']) | ||
expect(response.req.path).to.equal('/login'); | ||
}); | ||
}); | ||
|
||
it('authenticates and create the session when accessing authenticate route', function() { | ||
return request({ url: url + '/authenticate', jar: true }) | ||
.then(function(response) { | ||
|
||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%22authenticator%22%3A%22authenticator%3Aauth%22%2C%22account_id%22%3A%22123%22%7D%7D; path=/']) | ||
expect(response.req.path).to.equal('/'); | ||
}); | ||
}); | ||
|
||
it('user can access protected page after authentication', function() { | ||
return request({ url: url + '/protected', jar: true }) | ||
.then(function(response) { | ||
expect(response.req.path).to.equal('/protected'); | ||
expect(response.body).to.contain('This is a protected page only visible to authenticated users!'); | ||
}); | ||
}); | ||
|
||
it('invalidate removes session cookies', function() { | ||
return request({ url: url + '/invalidate', jar: true }) | ||
.then(function(response) { | ||
expect(response.req.path).to.equal('/invalidate'); | ||
expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D; path=/']) | ||
}); | ||
}); | ||
}); | ||
|
||
function addDependencies(app) { | ||
app.editPackageJSON(function(pkg) { | ||
pkg['devDependencies']['ember-cli-fastboot'] = "^1.0.0-beta.8"; | ||
}); | ||
return app.run('npm', 'install'); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Ember from 'ember'; | ||
import Resolver from './resolver'; | ||
import loadInitializers from 'ember-load-initializers'; | ||
import config from './config/environment'; | ||
|
||
const { Application } = Ember; | ||
|
||
let App; | ||
|
||
Ember.MODEL_FACTORY_INJECTIONS = true; | ||
|
||
App = Application.extend({ | ||
modulePrefix: config.modulePrefix, | ||
podModulePrefix: config.podModulePrefix, | ||
Resolver | ||
}); | ||
|
||
loadInitializers(App, config.modulePrefix); | ||
|
||
export default App; |
25 changes: 25 additions & 0 deletions
25
node-tests/fixtures/fastboot-app/app/authenticators/auth.js
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Ember from 'ember'; | ||
import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; | ||
|
||
const { RSVP: { resolve, reject }, inject: { service } } = Ember; | ||
|
||
export default BaseAuthenticator.extend({ | ||
session: service(), | ||
|
||
authenticate() { | ||
return resolve({ account_id: '123' }); | ||
}, | ||
|
||
invalidate() { | ||
return resolve(); | ||
}, | ||
|
||
restore(data) { | ||
if (this.get('session.shouldError')) { | ||
return reject(); | ||
} else { | ||
return resolve(data); | ||
} | ||
} | ||
|
||
}); |
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions
11
node-tests/fixtures/fastboot-app/app/controllers/application.js
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Ember from 'ember'; | ||
|
||
const { Controller } = Ember; | ||
|
||
export default Controller.extend({ | ||
actions: { | ||
transitionToLoginRoute() { | ||
this.transitionToRoute('login'); | ||
} | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title>Dummy</title> | ||
<meta name="description" content=""> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
{{content-for "head"}} | ||
|
||
<link rel="stylesheet" href="assets/vendor.css"> | ||
<link rel="stylesheet" href="assets/dummy.css"> | ||
|
||
{{content-for "head-footer"}} | ||
</head> | ||
<body> | ||
{{content-for "body"}} | ||
|
||
<script src="assets/vendor.js"></script> | ||
<script src="assets/dummy.js"></script> | ||
|
||
{{content-for "body-footer"}} | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Resolver from 'ember-resolver'; | ||
|
||
export default Resolver; |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Ember from 'ember'; | ||
import config from './config/environment'; | ||
|
||
const { Router: EmberRouter } = Ember; | ||
|
||
const Router = EmberRouter.extend({ | ||
location: config.locationType | ||
}); | ||
|
||
Router.map(function() { | ||
this.route('login'); | ||
this.route('protected'); | ||
this.route('authenticate'); | ||
this.route('invalidate'); | ||
}); | ||
|
||
export default Router; |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Ember from 'ember'; | ||
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; | ||
|
||
const { Route } = Ember; | ||
|
||
export default Route.extend(ApplicationRouteMixin, { | ||
|
||
}); |
11 changes: 11 additions & 0 deletions
11
node-tests/fixtures/fastboot-app/app/routes/authenticate.js
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import Ember from 'ember'; | ||
|
||
const { Route, inject: { service } } = Ember; | ||
|
||
export default Route.extend({ | ||
session: service('session'), | ||
|
||
model() { | ||
this.get('session').authenticate('authenticator:auth'); | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; | ||
|
||
const { Route, inject: { service } } = Ember; | ||
|
||
export default Route.extend(AuthenticatedRouteMixin, { | ||
session: service(), | ||
|
||
model() { | ||
this.get('session').invalidate(); | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Ember from 'ember'; | ||
import UnauthenticatedRouteMixin from 'ember-simple-auth/mixins/unauthenticated-route-mixin'; | ||
|
||
const { Route } = Ember; | ||
|
||
export default Route.extend(UnauthenticatedRouteMixin); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Ember from 'ember'; | ||
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin'; | ||
|
||
const { Route } = Ember; | ||
|
||
export default Route.extend(AuthenticatedRouteMixin, { | ||
}); |
3 changes: 3 additions & 0 deletions
3
node-tests/fixtures/fastboot-app/app/session-stores/application.js
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Cookie from 'ember-simple-auth/session-stores/cookie'; | ||
|
||
export default Cookie.extend(); |
Empty file.
3 changes: 3 additions & 0 deletions
3
node-tests/fixtures/fastboot-app/app/templates/application.hbs
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="container"> | ||
{{outlet}} | ||
</div> |
1 change: 1 addition & 0 deletions
1
node-tests/fixtures/fastboot-app/app/templates/authenticate.hbs
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{{outlet}} |
Empty file.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<h1>Ember Simple Auth example app</h1> |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="page-header"> | ||
<h1>Login</h1> | ||
</div> | ||
{{login-form}} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="page-header"> | ||
<h1>Protected Page</h1> | ||
</div> | ||
<div class="alert alert-warning"> | ||
This is a protected page only visible to authenticated users! | ||
</div> |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* jshint node: true */ | ||
|
||
module.exports = function(environment) { | ||
var ENV = { | ||
modulePrefix: 'fastboot-app', | ||
environment: environment, | ||
rootURL: '/', | ||
locationType: 'auto', | ||
EmberENV: { | ||
FEATURES: { | ||
// Here you can enable experimental features on an ember canary build | ||
// e.g. 'with-controller': true | ||
} | ||
}, | ||
|
||
APP: { | ||
// Here you can pass flags/options to your application instance | ||
// when it is created | ||
}, | ||
|
||
fastboot: { | ||
hostWhitelist:[/^localhost:\d+$/] | ||
}, | ||
}; | ||
|
||
if (environment === 'development') { | ||
// ENV.APP.LOG_RESOLVER = true; | ||
// ENV.APP.LOG_ACTIVE_GENERATION = true; | ||
// ENV.APP.LOG_TRANSITIONS = true; | ||
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true; | ||
// ENV.APP.LOG_VIEW_LOOKUPS = true; | ||
} | ||
|
||
if (environment === 'test') { | ||
// Testem prefers this... | ||
ENV.locationType = 'none'; | ||
|
||
// keep test console output quieter | ||
ENV.APP.LOG_ACTIVE_GENERATION = false; | ||
ENV.APP.LOG_VIEW_LOOKUPS = false; | ||
|
||
ENV.APP.rootElement = '#ember-testing'; | ||
} | ||
|
||
if (environment === 'production') { | ||
|
||
} | ||
|
||
return ENV; | ||
}; |
Oops, something went wrong.