-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fleet] Allow some agent actions for managed policies #155923
Merged
nchaulet
merged 7 commits into
elastic:main
from
nchaulet:feature-show-request-diagnostics-managed-policy
Apr 27, 2023
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
743a9ab
[Fleet] Show request diagnostics for managed policy in agent table
nchaulet af7b38d
Merge branch 'main' into feature-show-request-diagnostics-managed-policy
kibanamachine 06345bf
Merge branch 'main' of github.com:elastic/kibana into feature-show-re…
nchaulet 18d0269
show view json for managed policy too
nchaulet 21dbfd0
Merge branch 'feature-show-request-diagnostics-managed-policy' of git…
nchaulet a549e83
Show action menu for managed agents
nchaulet cc5aec7
Fix after review
nchaulet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
...lic/applications/fleet/sections/agents/agent_details_page/components/action_menu.test.tsx
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,168 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
|
||
import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
import type { Agent, AgentPolicy } from '../../../../types'; | ||
import { ExperimentalFeaturesService } from '../../../../services'; | ||
import { useAuthz } from '../../../../../../hooks/use_authz'; | ||
|
||
import { AgentDetailsActionMenu } from './actions_menu'; | ||
|
||
jest.mock('../../../../../../hooks/use_fleet_status', () => ({ | ||
FleetStatusProvider: (props: any) => { | ||
return props.children; | ||
}, | ||
})); | ||
|
||
jest.mock('../../../../../../services/experimental_features'); | ||
jest.mock('../../../../../../hooks/use_authz'); | ||
|
||
const mockedExperimentalFeaturesService = jest.mocked(ExperimentalFeaturesService); | ||
const mockedUseAuthz = jest.mocked(useAuthz); | ||
|
||
function renderActions({ agent, agentPolicy }: { agent: Agent; agentPolicy?: AgentPolicy }) { | ||
const renderer = createFleetTestRendererMock(); | ||
|
||
const utils = renderer.render( | ||
<AgentDetailsActionMenu | ||
agent={agent} | ||
agentPolicy={agentPolicy} | ||
assignFlyoutOpenByDefault={false} | ||
onCancelReassign={jest.fn()} | ||
/> | ||
); | ||
|
||
fireEvent.click(utils.getByRole('button')); | ||
|
||
return { utils }; | ||
} | ||
|
||
describe('AgentDetailsActionMenu', () => { | ||
beforeEach(() => { | ||
mockedExperimentalFeaturesService.get.mockReturnValue({ | ||
diagnosticFileUploadEnabled: true, | ||
} as any); | ||
mockedUseAuthz.mockReturnValue({ | ||
fleet: { | ||
all: true, | ||
}, | ||
} as any); | ||
}); | ||
|
||
describe('Request Diagnotics action', () => { | ||
function renderAndGetDiagnosticsButton({ | ||
agent, | ||
agentPolicy, | ||
}: { | ||
agent: Agent; | ||
agentPolicy?: AgentPolicy; | ||
}) { | ||
const { utils } = renderActions({ | ||
agent, | ||
agentPolicy, | ||
}); | ||
|
||
return utils.queryByTestId('requestAgentDiagnosticsBtn'); | ||
} | ||
|
||
it('should not render action if feature is disabled', async () => { | ||
mockedExperimentalFeaturesService.get.mockReturnValue({ | ||
diagnosticFileUploadEnabled: false, | ||
} as any); | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: {} as Agent, | ||
agentPolicy: {} as AgentPolicy, | ||
}); | ||
expect(res).toBe(null); | ||
}); | ||
|
||
it('should render an active action button if agent version >= 8.7', async () => { | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: { | ||
status: 'online', | ||
local_metadata: { elastic: { agent: { version: '8.8.0' } } }, | ||
} as any, | ||
agentPolicy: {} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).toBeEnabled(); | ||
}); | ||
|
||
it('should render an active action button if agent version >= 8.7 and policy is_managed', async () => { | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: { | ||
status: 'online', | ||
local_metadata: { elastic: { agent: { version: '8.8.0' } } }, | ||
} as any, | ||
agentPolicy: { | ||
is_managed: true, | ||
} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).toBeEnabled(); | ||
}); | ||
|
||
it('should render a disabled action button if agent version < 8.7', async () => { | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: { | ||
status: 'online', | ||
local_metadata: { elastic: { agent: { version: '8.6.0' } } }, | ||
} as any, | ||
agentPolicy: { | ||
is_managed: true, | ||
} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).not.toBeEnabled(); | ||
}); | ||
}); | ||
|
||
describe('View agent JSON action', () => { | ||
function renderAndGetViewJSONButton({ | ||
agent, | ||
agentPolicy, | ||
}: { | ||
agent: Agent; | ||
agentPolicy?: AgentPolicy; | ||
}) { | ||
const { utils } = renderActions({ | ||
agent, | ||
agentPolicy, | ||
}); | ||
|
||
return utils.queryByTestId('viewAgentDetailsJsonBtn'); | ||
} | ||
|
||
it('should render an active button', async () => { | ||
const res = renderAndGetViewJSONButton({ | ||
agent: {} as any, | ||
agentPolicy: {} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).toBeEnabled(); | ||
}); | ||
|
||
it('should render an active button for managed agent policy', async () => { | ||
const res = renderAndGetViewJSONButton({ | ||
agent: {} as any, | ||
agentPolicy: { | ||
is_managed: true, | ||
} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).toBeEnabled(); | ||
}); | ||
}); | ||
}); |
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
137 changes: 137 additions & 0 deletions
137
.../applications/fleet/sections/agents/agent_list_page/components/table_row_actions.test.tsx
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,137 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/dom'; | ||
|
||
import { createFleetTestRendererMock } from '../../../../../../mock'; | ||
import type { Agent, AgentPolicy } from '../../../../types'; | ||
import { ExperimentalFeaturesService } from '../../../../services'; | ||
import { useAuthz } from '../../../../../../hooks/use_authz'; | ||
|
||
import { TableRowActions } from './table_row_actions'; | ||
|
||
jest.mock('../../../../../../hooks/use_fleet_status', () => ({ | ||
FleetStatusProvider: (props: any) => { | ||
return props.children; | ||
}, | ||
})); | ||
|
||
jest.mock('../../../../../../services/experimental_features'); | ||
jest.mock('../../../../../../hooks/use_authz'); | ||
|
||
const mockedExperimentalFeaturesService = jest.mocked(ExperimentalFeaturesService); | ||
const mockedUseAuthz = jest.mocked(useAuthz); | ||
|
||
function renderTableRowActions({ | ||
agent, | ||
agentPolicy, | ||
}: { | ||
agent: Agent; | ||
agentPolicy?: AgentPolicy; | ||
}) { | ||
const renderer = createFleetTestRendererMock(); | ||
|
||
const utils = renderer.render( | ||
<TableRowActions | ||
agent={agent} | ||
agentPolicy={agentPolicy} | ||
onAddRemoveTagsClick={jest.fn()} | ||
onReassignClick={jest.fn()} | ||
onRequestDiagnosticsClick={jest.fn()} | ||
onUnenrollClick={jest.fn()} | ||
onUpgradeClick={jest.fn} | ||
/> | ||
); | ||
|
||
fireEvent.click(utils.getByTestId('agentActionsBtn')); | ||
|
||
return { utils }; | ||
} | ||
describe('TableRowActions', () => { | ||
beforeEach(() => { | ||
mockedExperimentalFeaturesService.get.mockReturnValue({ | ||
diagnosticFileUploadEnabled: true, | ||
} as any); | ||
mockedUseAuthz.mockReturnValue({ | ||
fleet: { | ||
all: true, | ||
}, | ||
} as any); | ||
}); | ||
|
||
describe('Request Diagnotics action', () => { | ||
function renderAndGetDiagnosticsButton({ | ||
agent, | ||
agentPolicy, | ||
}: { | ||
agent: Agent; | ||
agentPolicy?: AgentPolicy; | ||
}) { | ||
const { utils } = renderTableRowActions({ | ||
agent, | ||
agentPolicy, | ||
}); | ||
|
||
return utils.queryByTestId('requestAgentDiagnosticsBtn'); | ||
} | ||
|
||
it('should not render action if feature is disabled', async () => { | ||
mockedExperimentalFeaturesService.get.mockReturnValue({ | ||
diagnosticFileUploadEnabled: false, | ||
} as any); | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: {} as Agent, | ||
agentPolicy: {} as AgentPolicy, | ||
}); | ||
expect(res).toBe(null); | ||
}); | ||
|
||
it('should render an active action button if agent version >= 8.7', async () => { | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: { | ||
status: 'online', | ||
local_metadata: { elastic: { agent: { version: '8.8.0' } } }, | ||
} as any, | ||
agentPolicy: {} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).toBeEnabled(); | ||
}); | ||
|
||
it('should render an active action button if agent version >= 8.7 and policy is_managed', async () => { | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: { | ||
status: 'online', | ||
local_metadata: { elastic: { agent: { version: '8.8.0' } } }, | ||
} as any, | ||
agentPolicy: { | ||
is_managed: true, | ||
} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).toBeEnabled(); | ||
}); | ||
|
||
it('should render a disabled action button if agent version < 8.7', async () => { | ||
const res = renderAndGetDiagnosticsButton({ | ||
agent: { | ||
status: 'online', | ||
local_metadata: { elastic: { agent: { version: '8.6.0' } } }, | ||
} as any, | ||
agentPolicy: { | ||
is_managed: true, | ||
} as AgentPolicy, | ||
}); | ||
|
||
expect(res).not.toBe(null); | ||
expect(res).not.toBeEnabled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the UX would be less confusing if we hid these options instead of disabling them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure I will make the change