Skip to content

Commit

Permalink
add tests for update API
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokaditya committed Dec 19, 2022
1 parent 5a99585 commit 34519c6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
30 changes: 30 additions & 0 deletions x-pack/test/fleet_api_integration/apis/package_policy/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../api_integration/ftr_provider_context';
import { skipIfNoDockerRegistry } from '../../helpers';
import { testUsers } from '../test_users';

export default function (providerContext: FtrProviderContext) {
const { getService } = providerContext;
const supertest = getService('supertest');
const superTestWithoutAuth = getService('supertestWithoutAuth');
const dockerServers = getService('dockerServers');
const kibanaServer = getService('kibanaServer');

Expand Down Expand Up @@ -209,6 +211,34 @@ export default function (providerContext: FtrProviderContext) {
});
});

it('should return a 403 with package names that are not allowed', async function () {
await superTestWithoutAuth
.put(`/api/fleet/package_policies/${packagePolicyId}`)
.set('kbn-xsrf', 'xxxx')
.auth(
testUsers.endpoint_integr_write_policy.username,
testUsers.endpoint_integr_write_policy.password
)
.send({
name: 'updated_name',
description: '',
namespace: 'updated_namespace',
policy_id: managedAgentPolicyId,
enabled: true,
inputs: [],
package: {
name: 'filetest',
title: 'For File Tests',
version: '0.1.0',
},
})
.expect(403, {
error: 'Forbidden',
message: 'Update for package name filetest is not authorized.',
statusCode: 403,
});
});

it('should return a 400 if there is another package policy with the same name', async function () {
await supertest
.put(`/api/fleet/package_policies/${packagePolicyId2}`)
Expand Down
8 changes: 4 additions & 4 deletions x-pack/test/fleet_api_integration/apis/test_users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const testUsers: {
password: 'changeme',
},
// for package_policy get one, bulk get with ids, get list
any_integr_read_policy_read: {
endpoint_integr_read_policy: {
permissions: {
feature: {
fleet: ['read'],
Expand All @@ -89,19 +89,19 @@ export const testUsers: {
},
spaces: ['*'],
},
username: 'any_integr_read_policy_read',
username: 'endpoint_integr_read_policy',
password: 'changeme',
},
// for package_policy update API
any_integr_write_policy_write: {
endpoint_integr_write_policy: {
permissions: {
feature: {
fleet: ['all'],
siem: ['minimal_all', 'policy_management_all'],
},
spaces: ['*'],
},
username: 'any_integr_write_policy_write',
username: 'endpoint_integr_write_policy',
password: 'changeme',
},
};
Expand Down

0 comments on commit 34519c6

Please sign in to comment.