Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Oct 15, 2019
1 parent 12b998e commit 211caca
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Status = {
),
Inactive: (
<EuiHealth color="subdued">
<FormattedMessage id="xpack.fleet.agentHealth.offlineStatusText" defaultMessage="Inactive" />
<FormattedMessage id="xpack.fleet.agentHealth.inactiveStatusText" defaultMessage="Inactive" />
</EuiHealth>
),
Warning: (
Expand Down
54 changes: 54 additions & 0 deletions x-pack/legacy/plugins/fleet/server/libs/agent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@ describe('Agent lib', () => {
).rejects.toThrowError(/Agent not found/);
});

it('should throw is the agent is not active', async () => {
const token = new TokenLib({} as TokensRepository, {} as FrameworkLib);
const policy = new PolicyLib({} as PoliciesRepository);
const agentsRepository = new InMemoryAgentsRepository();
const agentsEventsRepository = new InMemoryAgentEventsRepository();
agentsRepository.agents['agent:1'] = ({
id: 'agent:1',
actions: [],
active: false,
policy_id: 'policy:1',
} as unknown) as Agent;
const agentLib = new AgentLib(agentsRepository, agentsEventsRepository, token, policy);

await expect(agentLib.checkin(getUser(), 'agent:1', [])).rejects.toThrowError(
/Agent inactive/
);
});

it('should persist new events', async () => {
const token = new TokenLib({} as TokensRepository, {} as FrameworkLib);
const policy = new PolicyLib({} as PoliciesRepository);
Expand Down Expand Up @@ -415,6 +433,42 @@ describe('Agent lib', () => {
});
});

describe('unenroll', () => {
it('should set the list of agents as inactive', async () => {
const token = new TokenLib({} as TokensRepository, {} as FrameworkLib);
const agentsRepository = new InMemoryAgentsRepository();
const agentEventsRepository = new InMemoryAgentEventsRepository();
agentsRepository.agents['agent:1'] = ({
id: 'agent:1',
local_metadata: { key: 'local1' },
user_provided_metadata: { key: 'user1' },
actions: [],
events: [],
active: true,
policy_id: 'policy:1',
} as unknown) as Agent;
agentsRepository.agents['agent:2'] = ({
id: 'agent:2',
local_metadata: { key: 'local1' },
user_provided_metadata: { key: 'user1' },
actions: [],
events: [],
active: true,
policy_id: 'policy:1',
} as unknown) as Agent;
const policy = new PolicyLib({} as PoliciesRepository);
const agentLib = new AgentLib(agentsRepository, agentEventsRepository, token, policy);

await agentLib.unenroll(getUser(), ['agent:1', 'agent:2']);

const refreshAgent1 = (await agentsRepository.getById(getUser(), 'agent:1')) as Agent;
const refreshAgent2 = (await agentsRepository.getById(getUser(), 'agent:2')) as Agent;

expect(refreshAgent1.active).toBeFalsy();
expect(refreshAgent2.active).toBeFalsy();
});
});

describe('addAction', () => {
it('should throw if the agent do not exists', async () => {
const token = new TokenLib({} as TokensRepository, {} as FrameworkLib);
Expand Down

0 comments on commit 211caca

Please sign in to comment.