-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI/managed namespace changes (#10588)
* Redirect to url with namespace param if user logged into root namespace without permission * Feature flag service for managing flags * Redirect with namespace query param if no current namespace param AND managed root namespace set * Test coverage for managed namespace changes * Handle null body case on feature-flag response, add pretender route for feature-flags on shamir test
- Loading branch information
Showing
17 changed files
with
228 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:feature | ||
ui: Adds check for feature flag on application, and updates namespace toolbar on login if present | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Service from '@ember/service'; | ||
|
||
const FLAGS = { | ||
vaultCloudNamespace: 'VAULT_CLOUD_ADMIN_NAMESPACE', | ||
}; | ||
|
||
export default Service.extend({ | ||
featureFlags: null, | ||
setFeatureFlags(flags) { | ||
this.set('featureFlags', flags); | ||
}, | ||
|
||
get managedNamespaceRoot() { | ||
if (this.featureFlags && this.featureFlags.includes(FLAGS.vaultCloudNamespace)) { | ||
return 'admin'; | ||
} | ||
return null; | ||
}, | ||
}); |
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
|
||
.field-label { | ||
margin-right: $spacing-s; | ||
align-self: center; | ||
} | ||
|
||
.is-label { | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Factory } from 'ember-cli-mirage'; | ||
|
||
export default Factory.extend({ | ||
feature_flags() { | ||
return []; // VAULT_CLOUD_ADMIN_NAMESPACE | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
import { Model } from 'ember-cli-mirage'; | ||
|
||
export default Model.extend({ | ||
feature_flags: null, | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export default function(server) { | ||
server.create('metrics/config'); | ||
server.create('feature', { feature_flags: ['SOME_FLAG', 'VAULT_CLOUD_ADMIN_NAMESPACE'] }); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { module, test } from 'qunit'; | ||
import { currentURL, visit, fillIn } from '@ember/test-helpers'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
import Pretender from 'pretender'; | ||
|
||
const FEATURE_FLAGS_RESPONSE = { | ||
data: { | ||
feature_flags: ['VAULT_CLOUD_ADMIN_NAMESPACE'], | ||
}, | ||
}; | ||
|
||
module('Acceptance | Enterprise | Managed namespace root', function(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
hooks.beforeEach(function() { | ||
/** | ||
* Since the features are fetched on the application load, | ||
* we have to populate them on the beforeEach hook because | ||
* the fetch won't trigger again within the tests | ||
*/ | ||
this.server = new Pretender(function() { | ||
this.get('/v1/sys/internal/ui/feature-flags', () => { | ||
return [200, { 'Content-Type': 'application/json' }, JSON.stringify(FEATURE_FLAGS_RESPONSE)]; | ||
}); | ||
this.get('/v1/sys/health', this.passthrough); | ||
this.get('/v1/sys/seal-status', this.passthrough); | ||
this.get('/v1/sys/license/features', this.passthrough); | ||
}); | ||
}); | ||
|
||
hooks.afterEach(function() { | ||
this.server.shutdown(); | ||
}); | ||
|
||
test('it shows the managed namespace toolbar when feature flag exists', async function(assert) { | ||
await visit('/vault/auth'); | ||
assert.equal(currentURL(), '/vault/auth?namespace=admin&with=token', 'Redirected to base namespace'); | ||
|
||
assert.dom('[data-test-namespace-toolbar]').doesNotExist('Normal namespace toolbar does not exist'); | ||
assert.dom('[data-test-managed-namespace-toolbar]').exists('Managed namespace toolbar exists'); | ||
assert.dom('[data-test-managed-namespace-root]').hasText('/admin', 'Shows /admin namespace prefix'); | ||
assert.dom('input#namespace').hasAttribute('placeholder', '/ (Default)'); | ||
await fillIn('input#namespace', '/foo'); | ||
let encodedNamespace = encodeURIComponent('admin/foo'); | ||
assert.equal( | ||
currentURL(), | ||
`/vault/auth?namespace=${encodedNamespace}&with=token`, | ||
'Correctly prepends root to namespace' | ||
); | ||
}); | ||
}); |
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,24 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
|
||
module('Unit | Service | feature-flag', function(hooks) { | ||
setupTest(hooks); | ||
|
||
test('it exists', function(assert) { | ||
let service = this.owner.lookup('service:feature-flag'); | ||
assert.ok(service); | ||
}); | ||
|
||
test('it returns the namespace root when flag is present', function(assert) { | ||
let service = this.owner.lookup('service:feature-flag'); | ||
assert.equal(service.managedNamespaceRoot, null, 'Managed namespace root is null by default'); | ||
service.setFeatureFlags(['VAULT_CLOUD_ADMIN_NAMESPACE']); | ||
assert.equal(service.managedNamespaceRoot, 'admin', 'Managed namespace is admin when flag present'); | ||
service.setFeatureFlags(['SOMETHING_ELSE']); | ||
assert.equal( | ||
service.managedNamespaceRoot, | ||
null, | ||
'Flags were overwritten and root namespace is null again' | ||
); | ||
}); | ||
}); |