-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable file transfer buttons if user lacks permissions (#49892)
This will disable the upload/download buttons in the web terminal if the user does not have the role option `ssh_file_copy`
- Loading branch information
Showing
11 changed files
with
179 additions
and
19 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
44 changes: 44 additions & 0 deletions
44
web/packages/shared/components/FileTransfer/FileTransferActionBar.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,44 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { render, screen } from 'design/utils/testing'; | ||
|
||
import { FileTransferActionBar } from './FileTransferActionBar'; | ||
import { FileTransferContextProvider } from './FileTransferContextProvider'; | ||
|
||
test('file transfer bar is enabled by default', async () => { | ||
render( | ||
<FileTransferContextProvider> | ||
<FileTransferActionBar hasAccess={true} isConnected={true} /> | ||
</FileTransferContextProvider> | ||
); | ||
|
||
expect(screen.getByTitle('Download files')).toBeEnabled(); | ||
expect(screen.getByTitle('Upload files')).toBeEnabled(); | ||
}); | ||
|
||
test('file transfer is disable if no access', async () => { | ||
render( | ||
<FileTransferContextProvider> | ||
<FileTransferActionBar hasAccess={false} isConnected={true} /> | ||
</FileTransferContextProvider> | ||
); | ||
|
||
expect(screen.getByTitle('Download files')).toBeDisabled(); | ||
expect(screen.getByTitle('Upload files')).toBeDisabled(); | ||
}); |
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
68 changes: 68 additions & 0 deletions
68
web/packages/teleport/src/Console/DocumentSsh/DocumentSsh.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,68 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { render, screen } from 'design/utils/testing'; | ||
import { MemoryRouter } from 'react-router'; | ||
import 'jest-canvas-mock'; | ||
|
||
import { allAccessAcl } from 'teleport/mocks/contexts'; | ||
|
||
import ConsoleContext from '../consoleContext'; | ||
import ConsoleContextProvider from '../consoleContextProvider'; | ||
|
||
import DocumentSsh from '.'; | ||
|
||
test('file transfer buttons are disabled if user does not have access', async () => { | ||
const ctx = new ConsoleContext(); | ||
ctx.storeUser.setState({ | ||
acl: { ...allAccessAcl, fileTransferAccess: false }, | ||
}); | ||
render(<Component ctx={ctx} />); | ||
expect(screen.getByTitle('Download files')).toBeDisabled(); | ||
}); | ||
|
||
test('file transfer buttons are enabled if user has access', async () => { | ||
const ctx = new ConsoleContext(); | ||
ctx.storeUser.setState({ | ||
acl: allAccessAcl, | ||
}); | ||
render(<Component ctx={ctx} />); | ||
expect(screen.getByTitle('Download files')).toBeEnabled(); | ||
}); | ||
|
||
function Component({ ctx }: { ctx: ConsoleContext }) { | ||
return ( | ||
<MemoryRouter> | ||
<ConsoleContextProvider value={ctx}> | ||
<DocumentSsh | ||
doc={{ | ||
id: 123, | ||
status: 'connected', | ||
kind: 'terminal', | ||
serverId: '123', | ||
login: 'tester', | ||
latency: { client: 123, server: 2 }, | ||
url: 'http://localhost', | ||
created: new Date(), | ||
}} | ||
visible={true} | ||
/> | ||
</ConsoleContextProvider> | ||
</MemoryRouter> | ||
); | ||
} |
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