Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
[server/csrf] don't tack helper methods onto kbnServer
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Nov 10, 2015
1 parent 6892b4a commit 5cdeae5
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/server/http/__tests__/xsrf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ const destructiveMethods = ['POST', 'PUT', 'DELETE'];
const src = resolve.bind(null, __dirname, '../../../../src');

describe('xsrf request filter', function () {
function inject(kbnServer, opts) {
return fn(cb => {
kbnServer.server.inject(opts, (resp) => {
cb(null, resp);
});
});
}

async function makeServer(token) {
const kbnServer = new KbnServer({
server: { autoListen: false, xsrf: { token } },
Expand All @@ -27,14 +35,6 @@ describe('xsrf request filter', function () {
}
});

kbnServer.inject = function (opts) {
return fn(cb => {
kbnServer.server.inject(opts, (resp) => {
cb(null, resp);
});
});
};

return kbnServer;
}

Expand All @@ -45,7 +45,7 @@ describe('xsrf request filter', function () {
afterEach(async () => await kbnServer.close());

it('sends a token when rendering an app', async function () {
var resp = await kbnServer.inject({
var resp = await inject(kbnServer, {
method: 'GET',
url: '/app/kibana',
});
Expand All @@ -60,7 +60,7 @@ describe('xsrf request filter', function () {
afterEach(async () => await kbnServer.close());

it('responds with a random token', async function () {
var resp = await kbnServer.inject({
var resp = await inject(kbnServer, {
method: 'GET',
url: '/app/kibana',
});
Expand All @@ -78,7 +78,7 @@ describe('xsrf request filter', function () {
for (const method of nonDestructiveMethods) {
context(`nonDestructiveMethod: ${method}`, function () { // eslint-disable-line no-loop-func
it('accepts requests without a token', async function () {
const resp = await kbnServer.inject({
const resp = await inject(kbnServer, {
url: '/xsrf/test/route',
method: method
});
Expand All @@ -88,7 +88,7 @@ describe('xsrf request filter', function () {
});

it('ignores invalid tokens', async function () {
const resp = await kbnServer.inject({
const resp = await inject(kbnServer, {
url: '/xsrf/test/route',
method: method,
headers: {
Expand All @@ -105,7 +105,7 @@ describe('xsrf request filter', function () {
for (const method of destructiveMethods) {
context(`destructiveMethod: ${method}`, function () { // eslint-disable-line no-loop-func
it('accepts requests with the correct token', async function () {
const resp = await kbnServer.inject({
const resp = await inject(kbnServer, {
url: '/xsrf/test/route',
method: method,
headers: {
Expand All @@ -118,7 +118,7 @@ describe('xsrf request filter', function () {
});

it('rejects requests without a token', async function () {
const resp = await kbnServer.inject({
const resp = await inject(kbnServer, {
url: '/xsrf/test/route',
method: method
});
Expand All @@ -128,7 +128,7 @@ describe('xsrf request filter', function () {
});

it('rejects requests with an invalid token', async function () {
const resp = await kbnServer.inject({
const resp = await inject(kbnServer, {
url: '/xsrf/test/route',
method: method,
headers: {
Expand Down

0 comments on commit 5cdeae5

Please sign in to comment.