Skip to content

Commit

Permalink
Adding more users to the spaces tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Sep 10, 2018
1 parent 4bbde73 commit 23515b1
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 357 deletions.
54 changes: 37 additions & 17 deletions x-pack/test/spaces_api_integration/common/suites/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ import { SuperTest } from 'supertest';
import { getUrlPrefix } from '../lib/space_test_utils';
import { DescribeFn, TestDefinitionAuthentication } from '../lib/types';

interface CreateTestWithoutSpace {
interface CreateTest {
statusCode: number;
response: (resp: any) => void;
}

interface CreateTestWithSpace {
statusCode: number;
space: any;
response: (resp: any) => void;
}

interface CreateTests {
newSpace: CreateTestWithSpace;
alreadyExists: CreateTestWithoutSpace;
reservedSpecified: CreateTestWithSpace;
newSpace: CreateTest;
alreadyExists: CreateTest;
reservedSpecified: CreateTest;
}

interface CreateTestDefinition {
Expand All @@ -45,7 +39,12 @@ export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
return supertest
.post(`${getUrlPrefix(spaceId)}/api/spaces/v1/space`)
.auth(auth.username, auth.password)
.send(tests.newSpace.space)
.send({
name: 'marketing',
id: 'marketing',
description: 'a description',
color: '#5c5959',
})
.expect(tests.newSpace.statusCode)
.then(tests.newSpace.response);
});
Expand All @@ -71,7 +70,13 @@ export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
return supertest
.post(`${getUrlPrefix(spaceId)}/api/spaces/v1/space`)
.auth(auth.username, auth.password)
.send(tests.reservedSpecified.space)
.send({
name: 'reserved space',
id: 'reserved',
description: 'a description',
color: '#5c5959',
_reserved: true,
})
.expect(tests.reservedSpecified.statusCode)
.then(tests.reservedSpecified.response);
});
Expand All @@ -81,10 +86,6 @@ export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any

const createTest = makeCreateTest(describe);

const createExpectResult = (expectedResult: any) => (resp: any) => {
expect(resp.body).to.eql(expectedResult);
};

const expectConflictResponse = (resp: any) => {
const spaceId = 'space_1';
expect(resp.body).to.only.have.keys(['error', 'message', 'statusCode']);
Expand All @@ -111,9 +112,28 @@ export function createTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
});
};

const expectNewSpaceResult = (resp: any) => {
expect(resp.body).to.eql({
name: 'marketing',
id: 'marketing',
description: 'a description',
color: '#5c5959',
});
};

const expectReservedSpecifiedResult = (resp: any) => {
expect(resp.body).to.eql({
name: 'reserved space',
id: 'reserved',
description: 'a description',
color: '#5c5959',
});
};

return {
createTest,
createExpectResult,
expectNewSpaceResult,
expectReservedSpecifiedResult,
expectConflictResponse,
expectRbacForbiddenResponse,
createExpectLegacyForbiddenResponse,
Expand Down
10 changes: 5 additions & 5 deletions x-pack/test/spaces_api_integration/common/suites/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ export function deleteTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
});
};

const expectRbacForbiddenResult = (resp: any) => {
const expectRbacForbidden = (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: 'Unauthorized to delete spaces',
});
};

const createExpectLegacyForbiddenResult = (username: string) => (resp: any) => {
const createExpectLegacyForbidden = (username: string, action: string) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: `action [indices:data/write/delete] is unauthorized for user [${username}]: [security_exception] action [indices:data/write/delete] is unauthorized for user [${username}]`,
message: `action [indices:data/${action}] is unauthorized for user [${username}]: [security_exception] action [indices:data/${action}] is unauthorized for user [${username}]`,
});
};

return {
deleteTest,
createExpectLegacyForbiddenResult,
createExpectLegacyForbidden,
createExpectResult,
expectRbacForbiddenResult,
expectRbacForbidden,
expectEmptyResult,
expectNotFoundResult,
expectReservedSpaceResult,
Expand Down
13 changes: 11 additions & 2 deletions x-pack/test/spaces_api_integration/common/suites/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,29 @@ export function getTestSuiteFactory(esArchiver: any, supertest: SuperAgent<any>)
});
};

const createExpectForbiddenResult = (spaceId: string) => (resp: any) => {
const createExpectRbacForbidden = (spaceId: string) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: `Unauthorized to get ${spaceId} space`,
});
};

const createExpectLegacyForbidden = (username: string) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: `action [indices:data/read/get] is unauthorized for user [${username}]: [security_exception] action [indices:data/read/get] is unauthorized for user [${username}]`,
});
};

return {
getTest,
nonExistantSpaceId,
createExpectResults,
createExpectForbiddenResult,
createExpectRbacForbidden,
createExpectEmptyResult,
createExpectNotFoundResult,
createExpectLegacyForbidden,
};
}
9 changes: 9 additions & 0 deletions x-pack/test/spaces_api_integration/common/suites/get_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,18 @@ export function getAllTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
expect(resp.body).to.eql('');
};

const createExpectLegacyForbidden = (username: string) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: `action [indices:data/read/search] is unauthorized for user [${username}]: [security_exception] action [indices:data/read/search] is unauthorized for user [${username}]`,
});
};

return {
getAllTest,
createExpectResults,
createExpectLegacyForbidden,
expectEmptyResult,
};
}
13 changes: 11 additions & 2 deletions x-pack/test/spaces_api_integration/common/suites/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function selectTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
message: `Saved object [space/${spaceId}] not found`,
});
};
const createExpectForbiddenResult = (spaceId: any) => (resp: any) => {
const createExpectRbacForbidden = (spaceId: any) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
Expand All @@ -108,14 +108,23 @@ export function selectTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
}
};

const createExpectLegacyForbidden = (username: string) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: `action [indices:data/read/get] is unauthorized for user [${username}]: [security_exception] action [indices:data/read/get] is unauthorized for user [${username}]`,
});
};

return {
selectTest,
nonExistantSpaceId,
expectDefaultSpaceResponse,
createExpectSpaceResponse,
createExpectResults,
createExpectForbiddenResult,
createExpectRbacForbidden,
createExpectEmptyResult,
createExpectNotFoundResult,
createExpectLegacyForbidden,
};
}
47 changes: 32 additions & 15 deletions x-pack/test/spaces_api_integration/common/suites/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { DescribeFn, TestDefinitionAuthentication } from '../lib/types';

interface UpdateTest {
statusCode: number;
space: any;
response: (resp: any) => void;
}

Expand All @@ -36,19 +35,30 @@ export function updateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any

it(`should return ${tests.alreadyExists.statusCode}`, async () => {
return supertest
.put(`${getUrlPrefix(spaceId)}/api/spaces/v1/space/${tests.alreadyExists.space.id}`)
.put(`${getUrlPrefix(spaceId)}/api/spaces/v1/space/space_1`)
.auth(auth.username, auth.password)
.send(tests.alreadyExists.space)
.send({
name: 'space 1',
id: 'space_1',
description: 'a description',
color: '#5c5959',
_reserved: true,
})
.expect(tests.alreadyExists.statusCode)
.then(tests.alreadyExists.response);
});

describe(`when space doesn't exist`, () => {
it(`should return ${tests.newSpace.statusCode}`, async () => {
return supertest
.put(`${getUrlPrefix(spaceId)}/api/spaces/v1/space/${tests.newSpace.space.id}`)
.put(`${getUrlPrefix(spaceId)}/api/spaces/v1/space/marketing`)
.auth(auth.username, auth.password)
.send(tests.newSpace.space)
.send({
name: 'marketing',
id: 'marketing',
description: 'a description',
color: '#5c5959',
})
.expect(tests.newSpace.statusCode)
.then(tests.newSpace.response);
});
Expand All @@ -58,10 +68,6 @@ export function updateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any

const updateTest = makeUpdateTest(describe);

const createExpectResult = (expectedResult: any) => (resp: any) => {
expect(resp.body).to.eql(expectedResult);
};

const createExpectNotFoundResult = (spaceId: string) => (resp: any) => {
expect(resp.body).to.eql({
error: 'Not Found',
Expand All @@ -70,27 +76,38 @@ export function updateTestSuiteFactory(esArchiver: any, supertest: SuperTest<any
});
};

const expectRbacForbiddenResult = (resp: any) => {
const expectRbacForbidden = (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: 'Unauthorized to update spaces',
});
};

const createExpectLegacyForbiddenResult = (username: string) => (resp: any) => {
const createExpectLegacyForbidden = (username: string) => (resp: any) => {
expect(resp.body).to.eql({
statusCode: 403,
error: 'Forbidden',
message: `action [indices:data/write/update] is unauthorized for user [${username}]: [security_exception] action [indices:data/write/update] is unauthorized for user [${username}]`,
});
};

const expectNewSpaceNotFound = createExpectNotFoundResult('marketing');

const expectAlreadyExistsResult = (resp: any) => {
expect(resp.body).to.eql({
name: 'space 1',
id: 'space_1',
description: 'a description',
color: '#5c5959',
});
};

return {
updateTest,
createExpectResult,
createExpectNotFoundResult,
expectRbacForbiddenResult,
createExpectLegacyForbiddenResult,
expectNewSpaceNotFound,
expectRbacForbidden,
createExpectLegacyForbidden,
expectAlreadyExistsResult,
};
}
Loading

0 comments on commit 23515b1

Please sign in to comment.