Add password type to models and mirage (#3039)
* feat: 🎸 add new password type to cred models + mirage * test: 💍 fix * refactor: 💡 update target mirage trait * chore: 🤖 add missing attr type
This commit is contained in:
1 parent
2bf09011fb
commit
f39961bbf5
8 files changed
+39
-14
No files matched your search
@@ -59,9 +59,9 @@ export default class GeneratedCredentialModel extends BaseModel {
|
||||
})
|
||||
username;
|
||||
|
||||
// =attributes (username_password, username_password_domain)
|
||||
// =attributes (username_password, username_password_domain, password)
|
||||
@attr('string', {
|
||||
for: ['username_password', 'username_password_domain'],
|
||||
for: ['username_password', 'username_password_domain', 'password'],
|
||||
isNestedAttribute: true,
|
||||
isSecret: true,
|
||||
description: 'The password for credential.',
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
} from 'api/models/credential';
|
||||
/**
|
||||
* Enum options for credential library.
|
||||
@@ -19,6 +20,7 @@ export const options = {
|
||||
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
],
|
||||
mapping_overrides: {
|
||||
username_password: ['username_attribute', 'password_attribute'],
|
||||
@@ -32,6 +34,7 @@ export const options = {
|
||||
'password_attribute',
|
||||
'domain_attribute',
|
||||
],
|
||||
password: ['password_attribute'],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -12,13 +12,16 @@ import GeneratedCredentialModel from '../generated/models/credential';
|
||||
export const TYPE_CREDENTIAL_USERNAME_PASSWORD = 'username_password';
|
||||
export const TYPE_CREDENTIAL_SSH_PRIVATE_KEY = 'ssh_private_key';
|
||||
export const TYPE_CREDENTIAL_JSON = 'json';
|
||||
export const TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN = 'username_password_domain';
|
||||
export const TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN =
|
||||
'username_password_domain';
|
||||
export const TYPE_CREDENTIAL_PASSWORD = 'password';
|
||||
|
||||
export const TYPES_CREDENTIAL = Object.freeze([
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
]);
|
||||
|
||||
export default class CredentialModel extends GeneratedCredentialModel {
|
||||
|
||||
@@ -65,7 +65,7 @@ export default factory.extend({
|
||||
break;
|
||||
case 'static':
|
||||
default:
|
||||
server.createList('credential', 3, {
|
||||
server.createList('credential', 5, {
|
||||
scope,
|
||||
credentialStore,
|
||||
});
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
TYPE_CREDENTIAL_SSH_PRIVATE_KEY,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
} from 'api/models/credential';
|
||||
|
||||
const types = [...TYPES_CREDENTIAL];
|
||||
@@ -20,14 +22,16 @@ export default factory.extend({
|
||||
type: (i) => types[i % types.length],
|
||||
id() {
|
||||
switch (this.type) {
|
||||
case 'ssh_private_key':
|
||||
case TYPE_CREDENTIAL_SSH_PRIVATE_KEY:
|
||||
return generatedId('credspk_');
|
||||
case 'username_password':
|
||||
case TYPE_CREDENTIAL_USERNAME_PASSWORD:
|
||||
return generatedId('credup_');
|
||||
case 'json':
|
||||
case TYPE_CREDENTIAL_JSON:
|
||||
return generatedId('credjson_');
|
||||
case 'username_password_domain':
|
||||
case TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN:
|
||||
return generatedId('credupd_');
|
||||
case TYPE_CREDENTIAL_PASSWORD:
|
||||
return generatedId('credp_');
|
||||
}
|
||||
},
|
||||
authorized_actions: () =>
|
||||
|
||||
@@ -17,7 +17,9 @@ import {
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
} from 'api/models/credential';
|
||||
import { TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP } from 'api/models/credential-library';
|
||||
|
||||
const randomBoolean = (chance = 0.5) => Math.random() < chance;
|
||||
const randomFilter = () =>
|
||||
@@ -111,7 +113,9 @@ export default factory.extend({
|
||||
server.schema.credentialLibraries,
|
||||
(cred) =>
|
||||
cred.scopeId === scope.id &&
|
||||
cred.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
cred.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN &&
|
||||
cred.credential_type !== TYPE_CREDENTIAL_PASSWORD &&
|
||||
cred.type !== TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
);
|
||||
const filteredCredentials = selectItems(
|
||||
server.schema.credentials,
|
||||
@@ -119,6 +123,7 @@ export default factory.extend({
|
||||
cred.scopeId === scope.id &&
|
||||
![
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
].includes(cred.type),
|
||||
);
|
||||
@@ -127,11 +132,12 @@ export default factory.extend({
|
||||
const filteredCredentialLibrariesForRDP = selectItems(
|
||||
server.schema.credentialLibraries,
|
||||
(cred) =>
|
||||
cred.scopeId === scope.id &&
|
||||
[
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
].includes(cred.credential_type),
|
||||
(cred.scopeId === scope.id &&
|
||||
[
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
].includes(cred.credential_type)) ||
|
||||
cred.type == TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP,
|
||||
);
|
||||
const filteredCredentialsForRDP = selectItems(
|
||||
server.schema.credentials,
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
{{!
|
||||
Copyright (c) HashiCorp, Inc.
|
||||
SPDX-License-Identifier: BUSL-1.1
|
||||
}}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
} from 'api/models/credential';
|
||||
import { setRunOptions } from 'ember-a11y-testing/test-support';
|
||||
|
||||
@@ -121,6 +122,7 @@ module(
|
||||
(cred) =>
|
||||
![
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
].includes(cred.type),
|
||||
);
|
||||
@@ -130,6 +132,7 @@ module(
|
||||
(cred) => {
|
||||
return (
|
||||
cred.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN &&
|
||||
cred.credential_type !== TYPE_CREDENTIAL_PASSWORD &&
|
||||
cred.type !== TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP
|
||||
);
|
||||
},
|
||||
@@ -191,6 +194,7 @@ module(
|
||||
this.server.schema.credentialLibraries.where((c) => {
|
||||
return (
|
||||
c.credential_type !== TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN &&
|
||||
c.credential_type !== TYPE_CREDENTIAL_PASSWORD &&
|
||||
c.type !== TYPE_CREDENTIAL_LIBRARY_VAULT_LDAP
|
||||
);
|
||||
}).models.length;
|
||||
@@ -200,6 +204,7 @@ module(
|
||||
(cred) =>
|
||||
![
|
||||
TYPE_CREDENTIAL_USERNAME_PASSWORD_DOMAIN,
|
||||
TYPE_CREDENTIAL_PASSWORD,
|
||||
TYPE_CREDENTIAL_JSON,
|
||||
].includes(cred.type),
|
||||
).models.length;
|
||||
|
||||
Reference in new issue
Block a user