-
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.
- Loading branch information
1 parent
cd14721
commit 5a3772f
Showing
27 changed files
with
362 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
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,45 @@ | ||
/* 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: ['--serve-assets'] | ||
}); | ||
}); | ||
}); | ||
|
||
after(function() { | ||
return app.stopServer(); | ||
}); | ||
|
||
it('redirects to login on protected route', function() { | ||
return request({ url: url }) | ||
.then(function(response) { | ||
expect(response.body).to.contain('Login'); | ||
}); | ||
}); | ||
}); | ||
|
||
function addDependencies(app) { | ||
app.editPackageJSON(function(pkg) { | ||
pkg['devDependencies']['ember-cli-fastboot'] = "*"; | ||
}); | ||
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; |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
import Ember from 'ember'; | ||
import BaseAuthenticator from 'ember-simple-auth/authenticators/base'; | ||
|
||
const { RSVP: { resolve } } = Ember; | ||
|
||
export default BaseAuthenticator.extend({ | ||
|
||
authenticate() { | ||
return resolve({ account_id: '123' }); | ||
}, | ||
|
||
invalidate() { | ||
return resolve(); | ||
}, | ||
|
||
restore(data) { | ||
return resolve(data); | ||
} | ||
|
||
}); |
Empty file.
13 changes: 13 additions & 0 deletions
13
node-tests/fixtures/fastboot-app/app/components/login-form.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,13 @@ | ||
import Ember from 'ember'; | ||
|
||
const { inject: { service }, Component } = Ember; | ||
|
||
export default Component.extend({ | ||
session: service('session'), | ||
|
||
actions: { | ||
authenticate() { | ||
this.get('session').authenticate('authenticator:auth'); | ||
}, | ||
} | ||
}); |
18 changes: 18 additions & 0 deletions
18
node-tests/fixtures/fastboot-app/app/components/main-navigation.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,18 @@ | ||
import Ember from 'ember'; | ||
|
||
const { inject: { service }, Component } = Ember; | ||
|
||
export default Component.extend({ | ||
session: service('session'), | ||
sessionAccount: service('session-account'), | ||
|
||
actions: { | ||
login() { | ||
this.sendAction('onLogin'); | ||
}, | ||
|
||
logout() { | ||
this.get('session').invalidate(); | ||
} | ||
} | ||
}); |
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; |
Empty file.
21 changes: 21 additions & 0 deletions
21
node-tests/fixtures/fastboot-app/app/routes/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,21 @@ | ||
import Ember from 'ember'; | ||
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; | ||
|
||
const { inject: { service }, Route } = Ember; | ||
|
||
export default Route.extend(ApplicationRouteMixin, { | ||
sessionAccount: service('session-account'), | ||
|
||
beforeModel() { | ||
return this._loadCurrentUser(); | ||
}, | ||
|
||
sessionAuthenticated() { | ||
this._super(...arguments); | ||
this._loadCurrentUser().catch(() => this.get('session').invalidate()); | ||
}, | ||
|
||
_loadCurrentUser() { | ||
return this.get('sessionAccount').loadCurrentUser(); | ||
} | ||
}); |
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, { | ||
}); |
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, { | ||
}); |
18 changes: 18 additions & 0 deletions
18
node-tests/fixtures/fastboot-app/app/services/session-account.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,18 @@ | ||
import Ember from 'ember'; | ||
|
||
const { inject: { service }, RSVP, Service, isEmpty } = Ember; | ||
|
||
export default Service.extend({ | ||
session: service('session'), | ||
|
||
loadCurrentUser() { | ||
return new RSVP.Promise((resolve) => { | ||
const accountId = this.get('session.data.authenticated.account_id'); | ||
if (!isEmpty(accountId)) { | ||
resolve({ name: 'Tomster' }); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
}); |
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(); |
4 changes: 4 additions & 0 deletions
4
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,4 @@ | ||
{{main-navigation onLogin='transitionToLoginRoute'}} | ||
<div class="container"> | ||
{{outlet}} | ||
</div> |
Empty file.
3 changes: 3 additions & 0 deletions
3
node-tests/fixtures/fastboot-app/app/templates/components/login-form.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 @@ | ||
<a {{action 'authenticate'}} class="btn btn-default"> | ||
Login with Auth | ||
</a> |
26 changes: 26 additions & 0 deletions
26
node-tests/fixtures/fastboot-app/app/templates/components/main-navigation.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,26 @@ | ||
<nav class="navbar navbar-default navbar-fixed-top"> | ||
<div class="container-fluid"> | ||
<div class="navbar-header"> | ||
{{#link-to 'index' classNames='navbar-brand'}} | ||
Home | ||
{{/link-to}} | ||
</div> | ||
<ul class="nav navbar-nav navbar-left"> | ||
{{#link-to 'protected' tagName='li'}} | ||
<a>Protected Page</a> | ||
{{/link-to}} | ||
{{#link-to 'auth-error' tagName='li'}} | ||
<a>Auth Error Page</a> | ||
{{/link-to}} | ||
</ul> | ||
{{! display logout button when the session is authenticated, login button otherwise }} | ||
{{#if session.isAuthenticated}} | ||
<a {{action 'logout'}} class="btn btn-danger navbar-btn navbar-right">Logout</a> | ||
{{#if sessionAccount.account}} | ||
<p class="navbar-text pull-right">Signed in as {{sessionAccount.account.name}}</p> | ||
{{/if}} | ||
{{else}} | ||
<a {{action 'login'}} class="btn btn-success navbar-btn navbar-right">Login</a> | ||
{{/if}} | ||
</div> | ||
</nav> |
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 @@ | ||
<div class="page-header"> | ||
<h1>Ember Simple Auth example app</h1> | ||
</div> | ||
{{#unless session.isAuthenticated}} | ||
<div class="alert alert-info"> | ||
You can {{#link-to 'login' classNames='alert-link'}}log in{{/link-to}} with login <code>letme</code> and password <code>in</code>. | ||
</div> | ||
{{/unless}} | ||
<div class="alert alert-info"> | ||
The dummy app provides two routes - the {{#link-to 'protected'}}Protected Page{{/link-to}} that loads some Ember Data models where the API validates that the request is authorized and the {{#link-to 'auth-error'}}Auth Error Page{{/link-to}} that simulates an authorization error (it loads Ember Data models as well but will always receive a 401 response) and will result in the session being invalidated. | ||
</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,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.