|
| 1 | +// Copyright (c) 2017-2023 Uber Technologies Inc. |
| 2 | +// |
| 3 | +// |
| 4 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | +// of this software and associated documentation files (the "Software"), to deal |
| 6 | +// in the Software without restriction, including without limitation the rights |
| 7 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | +// copies of the Software, and to permit persons to whom the Software is |
| 9 | +// furnished to do so, subject to the following conditions: |
| 10 | +// |
| 11 | +// The above copyright notice and this permission notice shall be included in |
| 12 | +// all copies or substantial portions of the Software. |
| 13 | +// |
| 14 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | +// THE SOFTWARE. |
| 21 | + |
| 22 | +import { getFixture } from './helpers'; |
| 23 | + |
| 24 | +const crossRegionSpecificFlags = [ |
| 25 | + 'crossRegion', |
| 26 | + 'crossRegion.activeStatusTag', |
| 27 | + 'crossRegion.allowedCrossOrigin', |
| 28 | + 'crossRegion.clusterOriginList', |
| 29 | +]; |
| 30 | + |
| 31 | +const featureFlagsForMultipleClustersEnv = [ |
| 32 | + ...getFixture('featureFlags').filter( |
| 33 | + ({ key }) => !crossRegionSpecificFlags.includes(key) |
| 34 | + ), |
| 35 | + { |
| 36 | + key: 'crossRegion', |
| 37 | + value: true, |
| 38 | + }, |
| 39 | + { |
| 40 | + key: 'crossRegion.activeStatusTag', |
| 41 | + value: true, |
| 42 | + }, |
| 43 | + { |
| 44 | + key: 'crossRegion.allowedCrossOrigin', |
| 45 | + value: true, |
| 46 | + }, |
| 47 | + { |
| 48 | + key: 'crossRegion.clusterOriginList', |
| 49 | + value: [ |
| 50 | + { |
| 51 | + clusterName: 'primary', |
| 52 | + origin: 'http://localhost:8090', |
| 53 | + }, |
| 54 | + { |
| 55 | + clusterName: 'ci-test-cluster', |
| 56 | + origin: 'http://localhost:8090', |
| 57 | + }, |
| 58 | + ], |
| 59 | + }, |
| 60 | +]; |
| 61 | + |
| 62 | +const featureFlagsForSingleClusterEnv = [ |
| 63 | + ...getFixture('featureFlags').filter( |
| 64 | + ({ key }) => !crossRegionSpecificFlags.includes(key) |
| 65 | + ), |
| 66 | + { |
| 67 | + key: 'crossRegion', |
| 68 | + value: false, |
| 69 | + }, |
| 70 | + { |
| 71 | + key: 'crossRegion.activeStatusTag', |
| 72 | + value: false, |
| 73 | + }, |
| 74 | + { |
| 75 | + key: 'crossRegion.allowedCrossOrigin', |
| 76 | + value: false, |
| 77 | + }, |
| 78 | + { |
| 79 | + key: 'crossRegion.clusterOriginList', |
| 80 | + value: [], |
| 81 | + }, |
| 82 | +]; |
| 83 | + |
| 84 | +describe('Domain ', () => { |
| 85 | + async function domainTest(mochaTest, { desc, featureFlags } = {}) { |
| 86 | + const [testEl, scenario] = new Scenario(mochaTest) |
| 87 | + .withCluster() |
| 88 | + .withDomain('ci-test') |
| 89 | + .withDomainAuthorization('ci-test', true) |
| 90 | + .withFeatureFlags(featureFlags) |
| 91 | + .withEmptyNewsFeed() |
| 92 | + .withDomainDescription('ci-test', desc) |
| 93 | + .withWorkflows({ status: 'open' }) |
| 94 | + .withWorkflows({ status: 'closed', startTimeOffset: 30 }) |
| 95 | + .startingAt('/domains/ci-test') |
| 96 | + .go(); |
| 97 | + |
| 98 | + const configEl = await testEl.waitUntilExists('section.domain'); |
| 99 | + |
| 100 | + return [testEl, scenario]; |
| 101 | + } |
| 102 | + |
| 103 | + it('should redirect to cluster if it is missing in the url in a cross region domain environment', async function test() { |
| 104 | + // if clusterName is missing in the url and active cluser exists |
| 105 | + // make sure to redirect to add cluster to url |
| 106 | + // we make sure the activeCluster config exists by passing feature flags for crossRegion configs |
| 107 | + const [testEl, scenario] = await domainTest(this.test, { |
| 108 | + featureFlags: featureFlagsForMultipleClustersEnv, |
| 109 | + }); |
| 110 | + |
| 111 | + await testEl.waitUntilExists('.feature-flag .active-status'); |
| 112 | + scenario.location.should.contain('/ci-test-cluster'); |
| 113 | + }); |
| 114 | + |
| 115 | + it('should not redirect to cluster if it is missing in the url in a non cross region domain environment', async function test() { |
| 116 | + const [testEl, scenario] = await domainTest(this.test, { |
| 117 | + featureFlags: featureFlagsForSingleClusterEnv, |
| 118 | + }); |
| 119 | + |
| 120 | + // make sure that cross region is not in the dom before asserting on the location |
| 121 | + const statusEl = await testEl |
| 122 | + .waitUntilExists('.feature-flag .active-status') |
| 123 | + .catch(() => { |
| 124 | + scenario.location.should.not.contain('/ci-test-cluster'); |
| 125 | + |
| 126 | + return null; |
| 127 | + }); |
| 128 | + |
| 129 | + (statusEl === null).should.equal(true); |
| 130 | + }); |
| 131 | +}); |
0 commit comments