Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve security cloud test failures #68935

Merged
merged 11 commits into from
Jun 16, 2020
10 changes: 5 additions & 5 deletions test/scripts/jenkins_xpack.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ if [[ -z "$CODE_COVERAGE" ]] ; then
echo ""
echo ""

# echo " -> Running jest integration tests"
# cd "$XPACK_DIR"
# node scripts/jest_integration --ci --verbose
# echo ""
# echo ""
echo " -> Running jest integration tests"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-enables jest integration tests on CI for x-pack as described in #67108 (comment)

cd "$XPACK_DIR"
node scripts/jest_integration --ci --verbose
echo ""
echo ""
else
echo " -> Running jest tests with coverage"
cd "$XPACK_DIR"
Expand Down
1 change: 1 addition & 0 deletions x-pack/dev-tools/jest/create_jest_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function createJestConfig({ kibanaDirectory, rootDir, xPackKibanaDirector
`${kibanaDirectory}/src/dev/jest/setup/react_testing_library.js`,
],
testMatch: ['**/*.test.{js,ts,tsx}'],
testPathIgnorePatterns: ['integration_tests/'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normal jest config should not run the integration tests. This is consistent with the OSS jest config.

transform: {
'^.+\\.(js|tsx?)$': `${kibanaDirectory}/src/dev/jest/babel_transform.js`,
'^.+\\.html?$': 'jest-raw-loader',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,30 @@
*/
import * as Rx from 'rxjs';
import Boom from 'boom';
import { Legacy } from 'kibana';
// @ts-ignore
import { kibanaTestUser } from '@kbn/test';
import { initSpacesOnRequestInterceptor } from './on_request_interceptor';
import { initSpacesOnRequestInterceptor } from '../on_request_interceptor';
import {
CoreSetup,
SavedObjectsErrorHelpers,
IBasePath,
IRouter,
} from '../../../../../../src/core/server';
} from '../../../../../../../src/core/server';
import {
elasticsearchServiceMock,
loggingServiceMock,
coreMock,
} from '../../../../../../src/core/server/mocks';
import * as kbnTestServer from '../../../../../../src/test_utils/kbn_server';
import { PluginsSetup } from '../../plugin';
import { SpacesService } from '../../spaces_service';
import { SpacesAuditLogger } from '../audit_logger';
import { convertSavedObjectToSpace } from '../../routes/lib';
import { initSpacesOnPostAuthRequestInterceptor } from './on_post_auth_interceptor';
import { Feature } from '../../../../features/server';
import { spacesConfig } from '../__fixtures__';
import { securityMock } from '../../../../security/server/mocks';

// FLAKY: https://github.com/elastic/kibana/issues/55953
describe.skip('onPostAuthInterceptor', () => {
} from '../../../../../../../src/core/server/mocks';
import * as kbnTestServer from '../../../../../../../src/test_utils/kbn_server';
import { PluginsSetup } from '../../../plugin';
import { SpacesService } from '../../../spaces_service';
import { SpacesAuditLogger } from '../../audit_logger';
import { convertSavedObjectToSpace } from '../../../routes/lib';
import { initSpacesOnPostAuthRequestInterceptor } from '../on_post_auth_interceptor';
import { Feature } from '../../../../../features/server';
import { spacesConfig } from '../../__fixtures__';
import { securityMock } from '../../../../../security/server/mocks';

describe('onPostAuthInterceptor', () => {
let root: ReturnType<typeof kbnTestServer.createRoot>;
jest.setTimeout(30000);

Expand All @@ -41,74 +38,25 @@ describe.skip('onPostAuthInterceptor', () => {
).toString('base64')}`,
};

/**
*
* commented out due to hooks being called regardless of skip
* https://github.com/facebook/jest/issues/8379

beforeEach(async () => {
root = kbnTestServer.createRoot();
});

afterEach(async () => await root.shutdown());

*/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests have been disabled for some time due to flakyness. Since we are mostly done with the legacy platform, I opted to remove the LP tests from this suite in order to simplify and reduce the chance of further flakyness. Tests for only the Kibana Platform are better than no tests at all.


function initKbnServer(router: IRouter, basePath: IBasePath, routes: 'legacy' | 'new-platform') {
const kbnServer = kbnTestServer.getKbnServer(root);

if (routes === 'legacy') {
kbnServer.server.route([
{
method: 'GET',
path: '/foo',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/app/kibana',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/app/app-1',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/app/app-2',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
{
method: 'GET',
path: '/api/test/foo',
handler: (req: Legacy.Request) => {
return { path: req.path, basePath: basePath.get(req) };
},
},
{
method: 'GET',
path: '/some/path/s/foo/bar',
handler: (req: Legacy.Request, h: Legacy.ResponseToolkit) => {
return h.response({ path: req.path, basePath: basePath.get(req) });
},
},
]);
}

if (routes === 'new-platform') {
router.get({ path: '/api/np_test/foo', validate: false }, (context, req, h) => {
return h.ok({ body: { path: req.url.pathname, basePath: basePath.get(req) } });
});
}
function initKbnServer(router: IRouter, basePath: IBasePath) {
router.get({ path: '/api/np_test/foo', validate: false }, (context, req, h) => {
return h.ok({ body: { path: req.url.pathname, basePath: basePath.get(req) } });
});
router.get({ path: '/app/kibana', validate: false }, (context, req, h) => {
return h.ok({ body: { path: req.url.pathname, basePath: basePath.get(req) } });
});
router.get({ path: '/app/app-1', validate: false }, (context, req, h) => {
return h.ok({ body: { path: req.url.pathname, basePath: basePath.get(req) } });
});
router.get({ path: '/app/app-2', validate: false }, (context, req, h) => {
return h.ok({ body: { path: req.url.pathname, basePath: basePath.get(req) } });
});
}

async function request(
Expand Down Expand Up @@ -213,105 +161,50 @@ describe.skip('onPostAuthInterceptor', () => {

const router = http.createRouter('/');

initKbnServer(router, http.basePath, 'new-platform');
initKbnServer(router, http.basePath);

await root.start();

initKbnServer(router, http.basePath, 'legacy');

const response = await kbnTestServer.request.get(root, path);

return {
response,
spacesService,
loggingMock,
};
}

describe('requests proxied to the legacy platform', () => {
it('redirects to the space selector screen when accessing an app within a non-existent space', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
},
},
];

const { response } = await request('/s/not-found/app/kibana', spaces);

expect(response.status).toEqual(302);
expect(response.header.location).toEqual(`/spaces/space_selector`);
});

it('when accessing the kibana app it always allows the request to continue', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
disabledFeatures: ['feature-1', 'feature-2', 'feature-4', 'feature-5'],
},
},
];

const { response } = await request('/s/a-space/app/kibana', spaces);

expect(response.status).toEqual(200);
});

it('allows the request to continue when accessing an API endpoint within a non-existent space', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
},
it('redirects to the space selector screen when accessing an app within a non-existent space', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
},
];
},
];

const { response } = await request('/s/not-found/api/test/foo', spaces);
const { response } = await request('/s/not-found/app/np_kibana', spaces);

expect(response.status).toEqual(200);
});
expect(response.status).toEqual(302);
expect(response.header.location).toEqual(`/spaces/space_selector`);
});

describe('requests handled completely in the new platform', () => {
it('redirects to the space selector screen when accessing an app within a non-existent space', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
},
},
];

const { response } = await request('/s/not-found/app/np_kibana', spaces);

expect(response.status).toEqual(302);
expect(response.header.location).toEqual(`/spaces/space_selector`);
});

it('allows the request to continue when accessing an API endpoint within a non-existent space', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
},
it('allows the request to continue when accessing an API endpoint within a non-existent space', async () => {
const spaces = [
{
id: 'a-space',
type: 'space',
attributes: {
name: 'a space',
},
];
},
];

const { response } = await request('/s/not-found/api/np_test/foo', spaces);
const { response } = await request('/s/not-found/api/np_test/foo', spaces);

expect(response.status).toEqual(200);
});
expect(response.status).toEqual(200);
});

it('handles space retrieval errors gracefully when requesting the root, responding with headers returned from ES', async () => {
Expand Down
Loading