Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Fix/default response content type #563

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/helpers/handle-accept-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ function handleAcceptRequest(req, res, handlers, fallbackHandler) {
// Accepted is an ordered list of preferred types, as specified by the request.
var accepted = req.accepts();
var produces = config.web.produces;
var defaultContentType = produces && produces.length >= 1
? produces[0]
: 'text/html';

// Our default response is HTML, if the client does not specify something more
// specific. As such, map the wildcard type to html.
// Our default response is the first entry in the `produces` array, if the
// request does not specify otherwise via the `Accepts` header.
accepted = accepted.map(function (contentType) {
return contentType === '*/*' ? 'text/html' : contentType;
return contentType === '*/*' ? defaultContentType : contentType;
});

// Of the accepted types, find the ones that are allowed by the configuration.
Expand Down
8 changes: 5 additions & 3 deletions test/controllers/test-email-verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ describe('email verification', function () {
web: {
register: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});
expressApp.on('stormpath.ready', done);
Expand Down Expand Up @@ -113,8 +114,8 @@ describe('email verification', function () {
var config = expressApp.get('stormpathConfig');
request(expressApp)
.post(config.web.verifyEmail.uri)
.send({ login: uuid() })
.set('Accept', 'application/json')
.send({ login: uuid() })
.expect(200, '', done);
});
});
Expand Down Expand Up @@ -206,7 +207,8 @@ describe('email verification', function () {
web:{
verifyEmail:{
uri: '/' + uuid()
}
},
produces: ['text/html']
}
});

Expand Down
18 changes: 12 additions & 6 deletions test/controllers/test-forgot-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ describe('forgotPassword', function () {
web: {
forgotPassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});

Expand Down Expand Up @@ -101,7 +102,8 @@ describe('forgotPassword', function () {
web: {
forgotPassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});

Expand Down Expand Up @@ -130,7 +132,8 @@ describe('forgotPassword', function () {
web: {
forgotPassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});

Expand All @@ -153,7 +156,8 @@ describe('forgotPassword', function () {
web: {
forgotPassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});

Expand All @@ -177,7 +181,8 @@ describe('forgotPassword', function () {
web: {
forgotPassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});

Expand All @@ -204,7 +209,8 @@ describe('forgotPassword', function () {
web: {
forgotPassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});
spaRootFixture.before(done);
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/test-id-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ describe('id site', function () {
},
idSite: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});

Expand Down
11 changes: 8 additions & 3 deletions test/controllers/test-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ describe('login', function () {

stormpathApplication = app;
defaultExpressApp = helpers.createStormpathExpressApp({
application: stormpathApplication
application: stormpathApplication,
web: {
produces: ['text/html', 'application/json']
}
});
alternateUrlExpressApp = helpers.createStormpathExpressApp({
application: stormpathApplication,
web: {
login: {
uri: '/newlogin'
}
},
produces: ['text/html', 'application/json']
}
});
app.createAccount(accountData, done);
Expand Down Expand Up @@ -240,7 +244,8 @@ describe('login', function () {
web: {
login: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});
spaRootFixture.before(done);
Expand Down
3 changes: 2 additions & 1 deletion test/controllers/test-logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('logout', function () {
},
accessTokenCookie: {
domain: 'example.com'
}
},
produces: ['text/html', 'application/json']
},
postLogoutHandler: postLogoutHandlerSpy
});
Expand Down
21 changes: 14 additions & 7 deletions test/controllers/test-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ function DefaultRegistrationFixture(stormpathApplication) {
web: {
register: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});
return this;
Expand Down Expand Up @@ -128,7 +129,8 @@ function NamesOptionalRegistrationFixture(stormpathApplication) {
}
}
}
}
},
produces: ['text/html', 'application/json']
}
});
return this;
Expand Down Expand Up @@ -191,7 +193,8 @@ function NamesDisabledRegistrationFixture(stormpathApplication) {
}
}
}
}
},
produces: ['text/html', 'application/json']
}
});
return this;
Expand Down Expand Up @@ -247,7 +250,8 @@ function CustomFieldRegistrationFixture(stormpathApplication) {
},
fieldOrder: ['givenName', 'surname', 'color', 'music', 'email', 'password']
}
}
},
produces: ['text/html', 'application/json']
}
});
return this;
Expand Down Expand Up @@ -405,7 +409,8 @@ describe('register', function () {
register: {
enabled: true,
uri: '/customRegistrationUri'
}
},
produces: ['text/html', 'application/json']
}
});
app.on('stormpath.ready', done);
Expand Down Expand Up @@ -687,7 +692,8 @@ describe('register', function () {
web: {
register: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});
spaRootFixture.before(done);
Expand Down Expand Up @@ -956,7 +962,8 @@ describe('register', function () {
autoLogin: true,
enabled: true,
nextUri: '/woot'
}
},
produces: ['text/html', 'application/json']
}
});
app.on('stormpath.ready', done);
Expand Down
8 changes: 6 additions & 2 deletions test/controllers/test-reset-password.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ describe('resetPassword', function () {
passwordResetToken = tokenResource.href.match(/\/([^\/]+)$/)[1];

defaultExpressApp = helpers.createStormpathExpressApp({
application: stormpathApplication
application: stormpathApplication,
web: {
produces: ['text/html', 'application/json']
}
});

defaultExpressApp.on('stormpath.ready', done);
Expand Down Expand Up @@ -320,7 +323,8 @@ describe('resetPassword', function () {
web: {
changePassword: {
enabled: true
}
},
produces: ['text/html', 'application/json']
}
});
spaRootFixture.before(done);
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/spa-root-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function SpaRootFixture(stormpathConfig) {
this.filename = '/tmp/' + uuid.v4();

if (!stormpathConfig.web) {
stormpathConfig.web = {};
stormpathConfig.web = {
produces: ['text/html', 'application/json']
};
}

stormpathConfig.web.spa = {
Expand Down
9 changes: 7 additions & 2 deletions test/handlers/test-post-registration-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function preparePostRegistrationExpansionTestFixture(stormpathApplication, cb) {
}
}
}
}
},
produces: ['text/html', 'application/json']
},
postRegistrationHandler: function (account, req, res) {
// Simply return the user object, so that we can
Expand Down Expand Up @@ -54,6 +55,9 @@ function preparePostRegistrationPassThroughTestFixture(stormpathApplication, cb)

fixture.expressApp = helpers.createStormpathExpressApp({
application: stormpathApplication,
web: {
produces: ['text/html', 'application/json']
},
postRegistrationHandler: function (account, req, res, next) {
fixture.sideEffect = fixture.sideEffectData;
next();
Expand All @@ -78,7 +82,8 @@ function preparePostRegistrationAutoLoginTestFixture(stormpathApplication, cb) {
register: {
enabled: true,
autoLogin: true
}
},
produces: ['text/html', 'application/json']
},
postRegistrationHandler: function (account, req, res, next) {
fixture.sideEffect = fixture.sideEffectData;
Expand Down
Loading