0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-01 02:41:39 -05:00

Added doAuth v2 admin api test helper (#9964)

* Fixed indentation for login function

no-issue

* Updated login to work with session auth

refs #9866

This allows the 201 response from session auth and will resolve with
the cookie, or the access_token if the cookie does not exist.

* Added basic doAuth to v2 admin test utils

refs #9866

This will allow functional tests to use session based authentication.
This commit is contained in:
Fabien O'Carroll 2018-10-09 10:24:41 +07:00 committed by GitHub
parent e392fe55ae
commit 05568fd9b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View file

@ -1,5 +1,6 @@
const url = require('url');
const _ = require('lodash');
const testUtils = require('../../../../utils');
const API_URL = '/ghost/api/v2/admin/';
module.exports = {
@ -7,5 +8,9 @@ module.exports = {
getApiQuery(route) {
return url.resolve(API_URL, route);
}
},
doAuth(...args) {
return testUtils.API.doAuth(`${API_URL}session/`, ...args);
}
};

View file

@ -149,15 +149,16 @@ const login = (request, API_URL) => {
password: 'Sl1m3rson99',
client_id: 'ghost-admin',
client_secret: 'not_available'
}).then(function then(res) {
if (res.statusCode !== 200) {
return reject(new common.errors.GhostError({
message: res.body.errors[0].message
}));
}
})
.then(function then(res) {
if (res.statusCode !== 200 && res.statusCode !== 201) {
return reject(new common.errors.GhostError({
message: res.body.errors[0].message
}));
}
resolve(res.body.access_token);
}, reject);
resolve(res.headers['set-cookie'] || res.body.access_token);
}, reject);
});
};