[ARVADOS-WORKBENCH2] updated: 2.2.1-74-g13036894
Git user
git at public.arvados.org
Wed Aug 25 05:29:52 UTC 2021
Summary of changes:
.../actions/collection-file-viewer-action.test.tsx | 117 +++++++++++++++++++++
1 file changed, 117 insertions(+)
create mode 100644 src/views-components/context-menu/actions/collection-file-viewer-action.test.tsx
via 1303689480b4e7df4d9d998a79c9c689453abc35 (commit)
from 1efa32ade334ede6836711218ab274a19525a22e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 1303689480b4e7df4d9d998a79c9c689453abc35
Author: Stephen Smith <stephen at curii.com>
Date: Wed Aug 25 01:28:36 2021 -0400
15159: Add unit tests for collection-file-viewer-action and TrustAllContent / secure URLs
Arvados-DCO-1.1-Signed-off-by: Stephen Smith <stephen at curii.com>
diff --git a/src/views-components/context-menu/actions/collection-file-viewer-action.test.tsx b/src/views-components/context-menu/actions/collection-file-viewer-action.test.tsx
new file mode 100644
index 00000000..8b90f588
--- /dev/null
+++ b/src/views-components/context-menu/actions/collection-file-viewer-action.test.tsx
@@ -0,0 +1,117 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import React from 'react';
+import { mount, configure } from 'enzyme';
+import Adapter from 'enzyme-adapter-react-16';
+import configureMockStore from 'redux-mock-store'
+import { Provider } from 'react-redux';
+import { CollectionFileViewerAction } from './collection-file-viewer-action';
+import { ContextMenuKind } from 'views-components/context-menu/context-menu';
+import { createTree, initTreeNode, setNode, getNodeValue } from "models/tree";
+import { getInlineFileUrl, sanitizeToken } from "./helpers";
+
+const middlewares = [];
+const mockStore = configureMockStore(middlewares);
+
+configure({ adapter: new Adapter() });
+
+describe('CollectionFileViewerAction', () => {
+ let defaultStore;
+ const fileUrl = "https://download.host:12345/c=abcde-4zz18-abcdefghijklmno/t=v2/token2/token3/cat.jpg";
+ const insecureKeepInlineUrl = "https://download.host:12345/";
+ const secureKeepInlineUrl = "https://*.collections.host:12345/";
+
+ beforeEach(() => {
+ let filesTree = createTree();
+ let data = {id: "000", value: {"url": fileUrl}};
+ filesTree = setNode(initTreeNode(data))(filesTree);
+
+ defaultStore = {
+ auth: {
+ config: {
+ keepWebServiceUrl: "https://download.host:12345/",
+ keepWebInlineServiceUrl: insecureKeepInlineUrl,
+ clusterConfig: {
+ Collections: {
+ TrustAllContent: false
+ }
+ }
+ }
+ },
+ contextMenu: {
+ resource: {
+ uuid: "000",
+ menuKind: ContextMenuKind.COLLECTION_FILE_ITEM,
+ }
+ },
+ collectionPanel: {
+ item: {
+ uuid: ""
+ }
+ },
+ collectionPanelFiles: filesTree
+ };
+ });
+
+ it('should hide open in new tab when unsafe', () => {
+ // given
+ const store = mockStore(defaultStore);
+
+ // when
+ const wrapper = mount(<Provider store={store}>
+ <CollectionFileViewerAction />
+ </Provider>);
+
+ // then
+ expect(wrapper).not.toBeUndefined();
+
+ // and
+ expect(wrapper.find("a")).toHaveLength(0);
+ });
+
+ it('should show open in new tab when TrustAllContent=true', () => {
+ // given
+ let initialState = defaultStore;
+ initialState.auth.config.clusterConfig.Collections.TrustAllContent = true;
+ const store = mockStore(initialState);
+
+ // when
+ const wrapper = mount(<Provider store={store}>
+ <CollectionFileViewerAction />
+ </Provider>);
+
+ // then
+ expect(wrapper).not.toBeUndefined();
+
+ // and
+ expect(wrapper.find("a").prop("href"))
+ .toEqual(sanitizeToken(getInlineFileUrl(fileUrl,
+ initialState.auth.config.keepWebServiceUrl,
+ initialState.auth.config.keepWebInlineServiceUrl))
+ );
+ });
+
+ it('should show open in new tab when inline url is secure', () => {
+ // given
+ let initialState = defaultStore;
+ initialState.auth.config.keepWebInlineServiceUrl = secureKeepInlineUrl;
+ const store = mockStore(initialState);
+
+ // when
+ const wrapper = mount(<Provider store={store}>
+ <CollectionFileViewerAction />
+ </Provider>);
+
+ // then
+ expect(wrapper).not.toBeUndefined();
+
+ // and
+ expect(wrapper.find("a").prop("href"))
+ .toEqual(sanitizeToken(getInlineFileUrl(fileUrl,
+ initialState.auth.config.keepWebServiceUrl,
+ initialState.auth.config.keepWebInlineServiceUrl))
+ );
+ });
+});
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list