Skip to content

Commit

Permalink
Fixing more functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
doakalexi committed Mar 29, 2023
1 parent 50f856d commit 51ab067
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/public/lib/common_transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function transformRule(input: ApiRule): Rule {
updated_at: updatedAt,
api_key: apiKey,
api_key_owner: apiKeyOwner,
api_key_created_by_user: apiKeyCreatedByUser,
notify_when: notifyWhen,
mute_all: muteAll,
muted_alert_ids: mutedInstanceIds,
Expand All @@ -130,6 +131,7 @@ export function transformRule(input: ApiRule): Rule {
updatedAt: new Date(updatedAt),
apiKey,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/clone_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const rewriteBodyRes: RewriteResponseCase<PartialRule<RuleTypeParams>> = ({
createdAt,
updatedAt,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down Expand Up @@ -75,6 +76,7 @@ const rewriteBodyRes: RewriteResponseCase<PartialRule<RuleTypeParams>> = ({
: {}),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
...(apiKeyCreatedByUser !== undefined ? { api_key_created_by_user: apiKeyCreatedByUser } : {}),
});

export const cloneRuleRoute = (
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/create_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
createdAt,
updatedAt,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down Expand Up @@ -93,6 +94,7 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
actions: rewriteActionsRes(actions),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
...(apiKeyCreatedByUser !== undefined ? { api_key_created_by_user: apiKeyCreatedByUser } : {}),
});

export const createRuleRoute = ({ router, licenseState, usageCounter }: RouteOptions) => {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/get_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
createdAt,
updatedAt,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down Expand Up @@ -77,6 +78,7 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
...(viewInAppRelativeUrl ? { view_in_app_relative_url: viewInAppRelativeUrl } : {}),
...(apiKeyCreatedByUser !== undefined ? { api_key_created_by_user: apiKeyCreatedByUser } : {}),
});

interface BuildGetRulesRouteParams {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/lib/rewrite_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const rewriteRule = ({
createdAt,
updatedAt,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down Expand Up @@ -75,4 +76,5 @@ export const rewriteRule = ({
})),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
...(apiKeyCreatedByUser !== undefined ? { api_key_created_by_user: apiKeyCreatedByUser } : {}),
});
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/resolve_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const rewriteBodyRes: RewriteResponseCase<ResolvedSanitizedRule<RuleTypeParams>>
createdAt,
updatedAt,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down Expand Up @@ -62,6 +63,7 @@ const rewriteBodyRes: RewriteResponseCase<ResolvedSanitizedRule<RuleTypeParams>>
actions: rewriteActionsRes(actions),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
...(apiKeyCreatedByUser !== undefined ? { api_key_created_by_user: apiKeyCreatedByUser } : {}),
});

export const resolveRuleRoute = (
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/alerting/server/routes/update_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const rewriteBodyRes: RewriteResponseCase<PartialRule<RuleTypeParams>> = ({
createdAt,
updatedAt,
apiKeyOwner,
apiKeyCreatedByUser,
notifyWhen,
muteAll,
mutedInstanceIds,
Expand Down Expand Up @@ -103,6 +104,7 @@ const rewriteBodyRes: RewriteResponseCase<PartialRule<RuleTypeParams>> = ({
: {}),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
...(apiKeyCreatedByUser !== undefined ? { api_key_created_by_user: apiKeyCreatedByUser } : {}),
});

export const updateRuleRoute = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ describe('apiKeyAsAlertAttributes', () => {
api_key: 'abc',
},
},
'test'
'test',
false
)
).toEqual({
apiKey: 'MTIzOmFiYw==',
apiKeyOwner: 'test',
apiKeyCreatedByUser: undefined,
apiKeyCreatedByUser: false,
});
});

Expand All @@ -34,11 +35,13 @@ describe('apiKeyAsAlertAttributes', () => {
{
apiKeysEnabled: false,
},
'test'
'test',
false
)
).toEqual({
apiKey: null,
apiKeyOwner: null,
apiKeyCreatedByUser: null,
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CreateAPIKeyResult } from '../types';
export function apiKeyAsAlertAttributes(
apiKey: CreateAPIKeyResult | null,
username: string | null,
createdByUser?: boolean
createdByUser: boolean
): Pick<RawRule, 'apiKey' | 'apiKeyOwner' | 'apiKeyCreatedByUser'> {
return apiKey && apiKey.apiKeysEnabled
? {
Expand All @@ -22,5 +22,6 @@ export function apiKeyAsAlertAttributes(
: {
apiKeyOwner: null,
apiKey: null,
apiKeyCreatedByUser: null,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function updateApiKeyWithOCC(context: RulesClientContext, { id }: { id: st

const updateAttributes = updateMeta(context, {
...attributes,
...apiKeyAsAlertAttributes(createdAPIKey, username),
...apiKeyAsAlertAttributes(createdAPIKey, username, false),
updatedAt: new Date().toISOString(),
updatedBy: username,
});
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/alerting/server/rules_client_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ test('creates a rules client with proper constructor arguments when security is
encryptedSavedObjectsClient: rulesClientFactoryParams.encryptedSavedObjectsClient,
kibanaVersion: '7.10.0',
minimumScheduleInterval: { value: '1m', enforce: false },
isAuthenticationTypeAPIKey: expect.any(Function),
getAuthenticationAPIKey: expect.any(Function),
});
});

Expand Down Expand Up @@ -160,6 +162,8 @@ test('creates a rules client with proper constructor arguments', async () => {
getEventLogClient: expect.any(Function),
kibanaVersion: '7.10.0',
minimumScheduleInterval: { value: '1m', enforce: false },
isAuthenticationTypeAPIKey: expect.any(Function),
getAuthenticationAPIKey: expect.any(Function),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const getTestUtils = (
notify_when: 'onThrottleInterval',
updated_by: 'elastic',
api_key_owner: 'elastic',
api_key_created_by_user: false,
mute_all: false,
muted_alert_ids: [],
execution_status: response.body.execution_status,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
enabled: true,
updated_by: user.username,
api_key_owner: user.username,
api_key_created_by_user: false,
mute_all: false,
muted_alert_ids: [],
actions: [
Expand Down Expand Up @@ -219,6 +220,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
enabled: true,
updated_by: user.username,
api_key_owner: user.username,
api_key_created_by_user: false,
mute_all: false,
muted_alert_ids: [],
scheduled_task_id: createdAlert.scheduled_task_id,
Expand Down Expand Up @@ -321,6 +323,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
enabled: true,
updated_by: user.username,
api_key_owner: user.username,
api_key_created_by_user: false,
mute_all: false,
muted_alert_ids: [],
scheduled_task_id: createdAlert.scheduled_task_id,
Expand Down Expand Up @@ -423,6 +426,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
enabled: true,
updated_by: user.username,
api_key_owner: user.username,
api_key_created_by_user: false,
mute_all: false,
muted_alert_ids: [],
scheduled_task_id: createdAlert.scheduled_task_id,
Expand Down Expand Up @@ -523,6 +527,7 @@ export default function createUpdateTests({ getService }: FtrProviderContext) {
enabled: true,
updated_by: user.username,
api_key_owner: user.username,
api_key_created_by_user: false,
mute_all: false,
muted_alert_ids: [],
scheduled_task_id: createdAlert.scheduled_task_id,
Expand Down

0 comments on commit 51ab067

Please sign in to comment.