-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fleet] Create a fleet_enroll user and role during fleet setup
- Loading branch information
Showing
7 changed files
with
181 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../ftr_provider_context'; | ||
|
||
export default function({ getService }: FtrProviderContext) { | ||
const supertest = getService('supertest'); | ||
const es = getService('es'); | ||
|
||
describe('fleet_setup', () => { | ||
before(async () => { | ||
try { | ||
await es.security.deleteUser({ | ||
username: 'fleet_enroll', | ||
}); | ||
} catch (e) { | ||
if (e.meta?.statusCode !== 404) { | ||
throw e; | ||
} | ||
} | ||
try { | ||
await es.security.deleteRole({ | ||
name: 'fleet_enroll', | ||
}); | ||
} catch (e) { | ||
if (e.meta?.statusCode !== 404) { | ||
throw e; | ||
} | ||
} | ||
}); | ||
|
||
it('should create a fleet_enroll user and role', async () => { | ||
const { body: apiResponse } = await supertest | ||
.post(`/api/ingest_manager/fleet/setup`) | ||
.set('kbn-xsrf', 'xxxx') | ||
.expect(200); | ||
|
||
expect(apiResponse.isInitialized).to.be(true); | ||
|
||
const { body: userResponse } = await es.security.getUser({ | ||
username: 'fleet_enroll', | ||
}); | ||
|
||
expect(userResponse).to.have.key('fleet_enroll'); | ||
expect(userResponse.fleet_enroll.roles).to.eql(['fleet_enroll']); | ||
|
||
const { body: roleResponse } = await es.security.getRole({ | ||
name: 'fleet_enroll', | ||
}); | ||
expect(roleResponse).to.have.key('fleet_enroll'); | ||
expect(roleResponse.fleet_enroll).to.eql({ | ||
cluster: ['monitor', 'manage_api_key'], | ||
indices: [ | ||
{ | ||
names: ['logs-*', 'metrics-*', 'events-*'], | ||
privileges: ['write', 'create_index'], | ||
allow_restricted_indices: false, | ||
}, | ||
], | ||
applications: [], | ||
run_as: [], | ||
metadata: {}, | ||
transient_metadata: { enabled: true }, | ||
}); | ||
}); | ||
}); | ||
} |