Skip to content

Commit

Permalink
Merge branch 'master' into fix/unsavedChangesSpaceSpecific
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Mar 1, 2021
2 parents b19b099 + b5cd44e commit 4632768
Show file tree
Hide file tree
Showing 19 changed files with 2,891 additions and 4,145,210 deletions.
24 changes: 16 additions & 8 deletions x-pack/plugins/case/server/saved_object_types/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,17 @@ export const userActionsMigrations = {

interface UnsanitizedComment {
comment: string;
type?: CommentType;
}

interface SanitizedComment {
comment: string;
type: CommentType;
}

interface SanitizedCommentFoSubCases {
interface SanitizedCommentForSubCases {
associationType: AssociationType;
rule: { id: string | null; name: string | null };
rule?: { id: string | null; name: string | null };
}

export const commentsMigrations = {
Expand All @@ -193,14 +194,21 @@ export const commentsMigrations = {
},
'7.12.0': (
doc: SavedObjectUnsanitizedDoc<UnsanitizedComment>
): SavedObjectSanitizedDoc<SanitizedCommentFoSubCases> => {
): SavedObjectSanitizedDoc<SanitizedCommentForSubCases> => {
let attributes: SanitizedCommentForSubCases & UnsanitizedComment = {
...doc.attributes,
associationType: AssociationType.case,
};

// only add the rule object for alert comments. Prior to 7.12 we only had CommentType.alert, generated alerts are
// introduced in 7.12.
if (doc.attributes.type === CommentType.alert) {
attributes = { ...attributes, rule: { id: null, name: null } };
}

return {
...doc,
attributes: {
...doc.attributes,
rule: { id: null, name: null },
associationType: AssociationType.case,
},
attributes,
references: doc.references || [],
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,32 @@ describe('CaseView ', () => {
});
});

it('should show the correct connector name on the push button', async () => {
useConnectorsMock.mockImplementation(() => ({ connectors: connectorsMock, loading: false }));
useGetCaseUserActionsMock.mockImplementation(() => ({
...defaultUseGetCaseUserActions,
hasDataToPush: true,
}));

const wrapper = mount(
<TestProviders>
<Router history={mockHistory}>
<CaseComponent {...{ ...caseProps, connector: { ...caseProps, name: 'old-name' } }} />
</Router>
</TestProviders>
);

await waitFor(() => {
expect(
wrapper
.find('[data-test-subj="has-data-to-push-button"]')
.first()
.text()
.includes('My Connector 2')
).toBe(true);
});
});

describe('Callouts', () => {
it('it shows the danger callout when a connector has been deleted', async () => {
useConnectorsMock.mockImplementation(() => ({ connectors: [], loading: false }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const CaseComponent = React.memo<CaseProps>(
const { pushButton, pushCallouts } = usePushToService({
connector: {
...caseData.connector,
name: isEmpty(caseData.connector.name) ? connectorName : caseData.connector.name,
name: isEmpty(connectorName) ? caseData.connector.name : connectorName,
},
caseServices,
caseId: caseData.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function ({ getService }: FtrProviderContext) {
fakePossibleCount: 3,
querySize: 1,
},
defaultIndex: ['auditbeat-*', 'filebeat-*', 'packetbeat-*', 'winlogbeat-*'],
defaultIndex: ['auditbeat-uncommon-processes'],
docValueFields: [],
inspect: false,
})
Expand Down Expand Up @@ -78,7 +78,7 @@ export default function ({ getService }: FtrProviderContext) {
fakePossibleCount: 3,
querySize: 2,
},
defaultIndex: ['auditbeat-*'],
defaultIndex: ['auditbeat-uncommon-processes'],
docValueFields: [],
inspect: false,
wait_for_completion_timeout: '10s',
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function ({ getService }: FtrProviderContext) {
fakePossibleCount: 3,
querySize: 1,
},
defaultIndex: ['auditbeat-*'],
defaultIndex: ['auditbeat-uncommon-processes'],
docValueFields: [],
inspect: false,
wait_for_completion_timeout: '10s',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function ({ getService }: FtrProviderContext) {
to: TO,
from: FROM,
},
defaultIndex: ['auditbeat-*'],
defaultIndex: ['auditbeat-users'],
docValueFields: [],
ip: IP,
flowTarget: FlowTarget.destination,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
await esArchiver.unload('cases/migrations/7.10.0');
});

it('7.11.0 migrates cases comments', async () => {
Expand Down
91 changes: 62 additions & 29 deletions x-pack/test/case_api_integration/basic/tests/cases/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,74 @@ export default function createGetTests({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
});
// tests upgrading a 7.10.0 saved object to the latest version
describe('7.10.0 -> latest stack version', () => {
before(async () => {
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
});
after(async () => {
await esArchiver.unload('cases/migrations/7.10.0');
});

it('migrates cases connector', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('connector');
expect(body).not.key('connector_id');
expect(body.connector).to.eql({
id: 'connector-1',
name: 'none',
type: '.none',
fields: null,
});
});

it('7.10.0 migrates cases connector', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('connector');
expect(body).not.key('connector_id');
expect(body.connector).to.eql({
id: 'connector-1',
name: 'none',
type: '.none',
fields: null,
it('migrates cases settings', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);

expect(body).key('settings');
expect(body.settings).to.eql({
syncAlerts: true,
});
});
});

it('7.11.0 migrates cases settings', async () => {
const { body } = await supertest
.get(`${CASES_URL}/e1900ac0-017f-11eb-93f8-d161651bf509`)
.set('kbn-xsrf', 'true')
.send()
.expect(200);
// tests upgrading a 7.11.1 saved object to the latest version
describe('7.11.1 -> latest stack version', () => {
const caseID = '2ea28c10-7855-11eb-9ca6-83ec5acb735f';
before(async () => {
await esArchiver.load('cases/migrations/7.11.1');
});

after(async () => {
await esArchiver.unload('cases/migrations/7.11.1');
});

it('adds rule info to only alert comments for 7.12', async () => {
// user comment
let { body } = await supertest
.get(`${CASES_URL}/${caseID}/comments/34a20a00-7855-11eb-9ca6-83ec5acb735f`)
.expect(200);

expect(body).not.key('rule');
expect(body.rule).to.eql(undefined);

// alert comment
({ body } = await supertest
.get(`${CASES_URL}/${caseID}/comments/3178f2b0-7857-11eb-9ca6-83ec5acb735f`)
.expect(200));

expect(body).key('settings');
expect(body.settings).to.eql({
syncAlerts: true,
expect(body).key('rule');
expect(body.rule).to.eql({ id: null, name: null });
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
await esArchiver.unload('cases/migrations/7.10.0');
});

it('7.10.0 migrates user actions connector', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {

describe('migrations', () => {
before(async () => {
await esArchiver.load('cases/migrations');
await esArchiver.load('cases/migrations/7.10.0');
});

after(async () => {
await esArchiver.unload('cases/migrations');
await esArchiver.unload('cases/migrations/7.10.0');
});

it('7.10.0 migrates configure cases connector', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "doc",
"value": {
"id": "HCFxB2kBR346wHgnL4ik",
"index": "auditbeat-8.0.0-2019.02.19-000001",
"index": "auditbeat-uncommon-processes",
"source": {
"@timestamp": "2019-02-19T20:27:31.074Z",
"agent": {
Expand Down Expand Up @@ -88,7 +88,7 @@
"type": "doc",
"value": {
"id": "AyJ8B2kBR346wHgnJDDU",
"index": "auditbeat-8.0.0-2019.02.19-000001",
"index": "auditbeat-uncommon-processes",
"source": {
"@timestamp": "2019-02-19T20:39:29.051Z",
"agent": {
Expand Down Expand Up @@ -173,7 +173,7 @@
"type": "doc",
"value": {
"id": "dSJ-B2kBR346wHgnV1E4",
"index": "auditbeat-8.0.0-2019.02.19-000001",
"index": "auditbeat-uncommon-processes",
"source": {
"@timestamp": "2019-02-19T20:41:53.180Z",
"agent": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"is_write_index": true
}
},
"index": "auditbeat-8.0.0-2019.02.19-000001",
"index": "auditbeat-uncommon-processes",
"mappings": {
"_meta": {
"beat": "auditbeat",
Expand Down
10 changes: 5 additions & 5 deletions x-pack/test/functional/es_archives/auditbeat/users/data.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"type": "doc",
"value": {
"index": "auditbeat-7.0.0-alpha1-2018.11.27",
"type": "doc",
"index": "auditbeat-users",
"type": "_doc",
"id": "Xa2ipWkBCQofM5eXEgsv",
"source": {
"@timestamp": "2018-11-27T02:59:28.060Z",
Expand All @@ -29,8 +29,7 @@
"session": "unset"
},
"destination" : {
"ip" : "0.0.0.0",
"port" : "22"
"ip" : "0.0.0.0"
},
"event": {
"type": "user_err",
Expand All @@ -51,7 +50,8 @@
"pid": "13647"
},
"source": {
"ip": "51.38.82.60"
"ip": "51.38.82.60",
"port": "22"
},
"network": {
"direction": "incoming"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "index",
"value": {
"index": "auditbeat-7.0.0-alpha1-2018.11.27",
"index": "auditbeat-users",
"settings": {
"index": {
"codec": "best_compression",
Expand Down Expand Up @@ -1900,4 +1900,4 @@
},
"aliases": {}
}
}
}
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 4632768

Please sign in to comment.