Moves credential mocks out to data json files

This commit is contained in:
mabashian
2020-04-23 15:53:36 -04:00
parent 428527052c
commit 67b826b438
6 changed files with 376 additions and 464 deletions

View File

@@ -6,7 +6,7 @@ import {
mountWithContexts,
waitForElement,
} from '../../../testUtils/enzymeHelpers';
import mockCredential from './shared/data.credential.json';
import mockCredential from './shared/data.scmCredential.json';
import mockOrgCredential from './shared/data.orgCredential.json';
import Credential from './Credential';

View File

@@ -1,472 +1,14 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { mountWithContexts } from '../../../../testUtils/enzymeHelpers';
import machineCredential from './data.machineCredential.json';
import gceCredential from './data.gceCredential.json';
import scmCredential from './data.scmCredential.json';
import credentialTypes from './data.credentialTypes.json';
import CredentialForm from './CredentialForm';
jest.mock('@api');
const machineCredential = {
id: 3,
type: 'credential',
url: '/api/v2/credentials/3/',
related: {
named_url: '/api/v2/credentials/oersdgfasf++Machine+ssh++org/',
created_by: '/api/v2/users/1/',
modified_by: '/api/v2/users/1/',
organization: '/api/v2/organizations/1/',
activity_stream: '/api/v2/credentials/3/activity_stream/',
access_list: '/api/v2/credentials/3/access_list/',
object_roles: '/api/v2/credentials/3/object_roles/',
owner_users: '/api/v2/credentials/3/owner_users/',
owner_teams: '/api/v2/credentials/3/owner_teams/',
copy: '/api/v2/credentials/3/copy/',
input_sources: '/api/v2/credentials/3/input_sources/',
credential_type: '/api/v2/credential_types/1/',
},
summary_fields: {
organization: {
id: 1,
name: 'org',
description: '',
},
credential_type: {
id: 1,
name: 'Machine',
description: '',
},
created_by: {
id: 1,
username: 'admin',
first_name: '',
last_name: '',
},
modified_by: {
id: 1,
username: 'admin',
first_name: '',
last_name: '',
},
object_roles: {
admin_role: {
description: 'Can manage all aspects of the credential',
name: 'Admin',
id: 36,
},
use_role: {
description: 'Can use the credential in a job template',
name: 'Use',
id: 37,
},
read_role: {
description: 'May view settings for the credential',
name: 'Read',
id: 38,
},
},
user_capabilities: {
edit: true,
delete: true,
copy: true,
use: true,
},
owners: [
{
id: 1,
type: 'user',
name: 'admin',
description: ' ',
url: '/api/v2/users/1/',
},
{
id: 1,
type: 'organization',
name: 'org',
description: '',
url: '/api/v2/organizations/1/',
},
],
},
created: '2020-02-18T15:35:04.563928Z',
modified: '2020-02-18T15:35:04.563957Z',
name: 'oersdgfasf',
description: '',
organization: 1,
credential_type: 1,
inputs: {},
kind: 'ssh',
cloud: false,
kubernetes: false,
};
const sourceControlCredential = {
id: 4,
type: 'credential',
url: '/api/v2/credentials/4/',
related: {
named_url: '/api/v2/credentials/joijoij++Source Control+scm++/',
created_by: '/api/v2/users/1/',
modified_by: '/api/v2/users/1/',
activity_stream: '/api/v2/credentials/4/activity_stream/',
access_list: '/api/v2/credentials/4/access_list/',
object_roles: '/api/v2/credentials/4/object_roles/',
owner_users: '/api/v2/credentials/4/owner_users/',
owner_teams: '/api/v2/credentials/4/owner_teams/',
copy: '/api/v2/credentials/4/copy/',
input_sources: '/api/v2/credentials/4/input_sources/',
credential_type: '/api/v2/credential_types/2/',
user: '/api/v2/users/1/',
},
summary_fields: {
credential_type: {
id: 2,
name: 'Source Control',
description: '',
},
created_by: {
id: 1,
username: 'admin',
first_name: '',
last_name: '',
},
modified_by: {
id: 1,
username: 'admin',
first_name: '',
last_name: '',
},
object_roles: {
admin_role: {
description: 'Can manage all aspects of the credential',
name: 'Admin',
id: 39,
},
use_role: {
description: 'Can use the credential in a job template',
name: 'Use',
id: 40,
},
read_role: {
description: 'May view settings for the credential',
name: 'Read',
id: 41,
},
},
user_capabilities: {
edit: true,
delete: true,
copy: true,
use: true,
},
owners: [
{
id: 1,
type: 'user',
name: 'admin',
description: ' ',
url: '/api/v2/users/1/',
},
],
},
created: '2020-02-18T16:03:01.366287Z',
modified: '2020-02-18T16:03:01.366315Z',
name: 'joijoij',
description: 'ojiojojo',
organization: null,
credential_type: 2,
inputs: {
ssh_key_unlock: '$encrypted$',
},
kind: 'scm',
cloud: false,
kubernetes: false,
};
const gceCredential = {
id: 9,
type: 'credential',
url: '/api/v2/credentials/9/',
related: {
named_url:
'/api/v2/credentials/a gce cred++Google Compute Engine+cloud++Default/',
created_by: '/api/v2/users/1/',
modified_by: '/api/v2/users/1/',
organization: '/api/v2/organizations/4/',
activity_stream: '/api/v2/credentials/9/activity_stream/',
access_list: '/api/v2/credentials/9/access_list/',
object_roles: '/api/v2/credentials/9/object_roles/',
owner_users: '/api/v2/credentials/9/owner_users/',
owner_teams: '/api/v2/credentials/9/owner_teams/',
copy: '/api/v2/credentials/9/copy/',
input_sources: '/api/v2/credentials/9/input_sources/',
credential_type: '/api/v2/credential_types/10/',
},
summary_fields: {
organization: {
id: 4,
name: 'Default',
description: '',
},
credential_type: {
id: 10,
name: 'Google Compute Engine',
description: '',
},
created_by: {
id: 1,
username: 'admin',
first_name: '',
last_name: '',
},
modified_by: {
id: 1,
username: 'admin',
first_name: '',
last_name: '',
},
object_roles: {
admin_role: {
description: 'Can manage all aspects of the credential',
name: 'Admin',
id: 287,
},
use_role: {
description: 'Can use the credential in a job template',
name: 'Use',
id: 288,
},
read_role: {
description: 'May view settings for the credential',
name: 'Read',
id: 289,
},
},
user_capabilities: {
edit: true,
delete: true,
copy: true,
use: true,
},
owners: [
{
id: 1,
type: 'user',
name: 'admin',
description: ' ',
url: '/api/v2/users/1/',
},
{
id: 4,
type: 'organization',
name: 'Default',
description: '',
url: '/api/v2/organizations/4/',
},
],
},
created: '2020-04-13T17:33:27.625773Z',
modified: '2020-04-13T17:33:27.625882Z',
name: 'a gce cred',
description: '',
organization: 4,
credential_type: 10,
inputs: {
project: 'test123',
username: 'test123.iam.gserviceaccount.com',
ssh_key_data: '$encrypted$',
},
kind: 'gce',
cloud: true,
kubernetes: false,
};
const credentialTypes = [
{
id: 2,
type: 'credential_type',
url: '/api/v2/credential_types/2/',
related: {
credentials: '/api/v2/credential_types/2/credentials/',
activity_stream: '/api/v2/credential_types/2/activity_stream/',
},
summary_fields: {
user_capabilities: {
edit: false,
delete: false,
},
},
created: '2020-02-12T19:42:43.551238Z',
modified: '2020-02-12T19:43:03.164800Z',
name: 'Source Control',
description: '',
kind: 'scm',
namespace: 'scm',
managed_by_tower: true,
inputs: {
fields: [
{
id: 'username',
label: 'Username',
type: 'string',
},
{
id: 'password',
label: 'Password',
type: 'string',
secret: true,
},
{
id: 'ssh_key_data',
label: 'Source Control Private Key',
type: 'string',
format: 'ssh_private_key',
secret: true,
multiline: true,
},
{
id: 'ssh_key_unlock',
label: 'Private Key Passphrase',
type: 'string',
secret: true,
},
],
},
injectors: {},
},
{
id: 1,
type: 'credential_type',
url: '/api/v2/credential_types/1/',
related: {
credentials: '/api/v2/credential_types/1/credentials/',
activity_stream: '/api/v2/credential_types/1/activity_stream/',
},
summary_fields: {
user_capabilities: {
edit: false,
delete: false,
},
},
created: '2020-02-12T19:42:43.539626Z',
modified: '2020-02-12T19:43:03.159739Z',
name: 'Machine',
description: '',
kind: 'ssh',
namespace: 'ssh',
managed_by_tower: true,
inputs: {
fields: [
{
id: 'username',
label: 'Username',
type: 'string',
},
{
id: 'password',
label: 'Password',
type: 'string',
secret: true,
ask_at_runtime: true,
},
{
id: 'ssh_key_data',
label: 'SSH Private Key',
type: 'string',
format: 'ssh_private_key',
secret: true,
multiline: true,
},
{
id: 'ssh_public_key_data',
label: 'Signed SSH Certificate',
type: 'string',
multiline: true,
secret: true,
},
{
id: 'ssh_key_unlock',
label: 'Private Key Passphrase',
type: 'string',
secret: true,
ask_at_runtime: true,
},
{
id: 'become_method',
label: 'Privilege Escalation Method',
type: 'string',
help_text:
'Specify a method for "become" operations. This is equivalent to specifying the --become-method Ansible parameter.',
},
{
id: 'become_username',
label: 'Privilege Escalation Username',
type: 'string',
},
{
id: 'become_password',
label: 'Privilege Escalation Password',
type: 'string',
secret: true,
ask_at_runtime: true,
},
],
},
injectors: {},
},
{
id: 10,
type: 'credential_type',
url: '/api/v2/credential_types/10/',
related: {
credentials: '/api/v2/credential_types/10/credentials/',
activity_stream: '/api/v2/credential_types/10/activity_stream/',
},
summary_fields: {
user_capabilities: {
edit: false,
delete: false,
},
},
created: '2020-04-09T19:20:27.090665Z',
modified: '2020-04-09T19:21:11.575214Z',
name: 'Google Compute Engine',
description: '',
kind: 'cloud',
namespace: 'gce',
managed_by_tower: true,
inputs: {
fields: [
{
id: 'username',
label: 'Service Account Email Address',
type: 'string',
help_text:
'The email address assigned to the Google Compute Engine service account.',
},
{
id: 'project',
label: 'Project',
type: 'string',
help_text:
'The Project ID is the GCE assigned identification. It is often constructed as three words or two words followed by a three-digit number. Examples: project-id-000 and another-project-id',
},
{
id: 'ssh_key_data',
label: 'RSA Private Key',
type: 'string',
format: 'ssh_private_key',
secret: true,
multiline: true,
help_text:
'Paste the contents of the PEM file associated with the service account email.',
},
],
required: ['username', 'ssh_key_data'],
},
injectors: {},
},
];
describe('<CredentialForm />', () => {
let wrapper;
const onCancel = jest.fn();
@@ -704,7 +246,7 @@ describe('<CredentialForm />', () => {
<CredentialForm
onCancel={onCancel}
onSubmit={onSubmit}
credential={sourceControlCredential}
credential={scmCredential}
credentialTypes={credentialTypes}
/>
);

View File

@@ -0,0 +1,182 @@
[
{
"id": 2,
"type": "credential_type",
"url": "/api/v2/credential_types/2/",
"related": {
"credentials": "/api/v2/credential_types/2/credentials/",
"activity_stream": "/api/v2/credential_types/2/activity_stream/"
},
"summary_fields": {
"user_capabilities": {
"edit": false,
"delete": false
}
},
"created": "2020-02-12T19:42:43.551238Z",
"modified": "2020-02-12T19:43:03.164800Z",
"name": "Source Control",
"description": "",
"kind": "scm",
"namespace": "scm",
"managed_by_tower": true,
"inputs": {
"fields": [
{
"id": "username",
"label": "Username",
"type": "string"
},
{
"id": "password",
"label": "Password",
"type": "string",
"secret": true
},
{
"id": "ssh_key_data",
"label": "Source Control Private Key",
"type": "string",
"format": "ssh_private_key",
"secret": true,
"multiline": true
},
{
"id": "ssh_key_unlock",
"label": "Private Key Passphrase",
"type": "string",
"secret": true
}
]
},
"injectors": {}
},
{
"id": 1,
"type": "credential_type",
"url": "/api/v2/credential_types/1/",
"related": {
"credentials": "/api/v2/credential_types/1/credentials/",
"activity_stream": "/api/v2/credential_types/1/activity_stream/"
},
"summary_fields": {
"user_capabilities": {
"edit": false,
"delete": false
}
},
"created": "2020-02-12T19:42:43.539626Z",
"modified": "2020-02-12T19:43:03.159739Z",
"name": "Machine",
"description": "",
"kind": "ssh",
"namespace": "ssh",
"managed_by_tower": true,
"inputs": {
"fields": [
{
"id": "username",
"label": "Username",
"type": "string"
},
{
"id": "password",
"label": "Password",
"type": "string",
"secret": true,
"ask_at_runtime": true
},
{
"id": "ssh_key_data",
"label": "SSH Private Key",
"type": "string",
"format": "ssh_private_key",
"secret": true,
"multiline": true
},
{
"id": "ssh_public_key_data",
"label": "Signed SSH Certificate",
"type": "string",
"multiline": true,
"secret": true
},
{
"id": "ssh_key_unlock",
"label": "Private Key Passphrase",
"type": "string",
"secret": true,
"ask_at_runtime": true
},
{
"id": "become_method",
"label": "Privilege Escalation Method",
"type": "string",
"help_text": "Specify a method for \"become\" operations. This is equivalent to specifying the --become-method Ansible parameter."
},
{
"id": "become_username",
"label": "Privilege Escalation Username",
"type": "string"
},
{
"id": "become_password",
"label": "Privilege Escalation Password",
"type": "string",
"secret": true,
"ask_at_runtime": true
}
]
},
"injectors": {}
},
{
"id": 10,
"type": "credential_type",
"url": "/api/v2/credential_types/10/",
"related": {
"credentials": "/api/v2/credential_types/10/credentials/",
"activity_stream": "/api/v2/credential_types/10/activity_stream/"
},
"summary_fields": {
"user_capabilities": {
"edit": false,
"delete": false
}
},
"created": "2020-04-09T19:20:27.090665Z",
"modified": "2020-04-09T19:21:11.575214Z",
"name": "Google Compute Engine",
"description": "",
"kind": "cloud",
"namespace": "gce",
"managed_by_tower": true,
"inputs": {
"fields": [
{
"id": "username",
"label": "Service Account Email Address",
"type": "string",
"help_text": "The email address assigned to the Google Compute Engine service account."
},
{
"id": "project",
"label": "Project",
"type": "string",
"help_text": "The Project ID is the GCE assigned identification. It is often constructed as three words or two words followed by a three-digit number. Examples: project-id-000 and another-project-id"
},
{
"id": "ssh_key_data",
"label": "RSA Private Key",
"type": "string",
"format": "ssh_private_key",
"secret": true,
"multiline": true,
"help_text": "Paste the contents of the PEM file associated with the service account email."
}
],
"required": ["username", "ssh_key_data"]
},
"injectors": {}
}
]

View File

@@ -0,0 +1,96 @@
{
"id": 9,
"type": "credential",
"url": "/api/v2/credentials/9/",
"related": {
"named_url": "/api/v2/credentials/a gce cred++Google Compute Engine+cloud++Default/",
"created_by": "/api/v2/users/1/",
"modified_by": "/api/v2/users/1/",
"organization": "/api/v2/organizations/4/",
"activity_stream": "/api/v2/credentials/9/activity_stream/",
"access_list": "/api/v2/credentials/9/access_list/",
"object_roles": "/api/v2/credentials/9/object_roles/",
"owner_users": "/api/v2/credentials/9/owner_users/",
"owner_teams": "/api/v2/credentials/9/owner_teams/",
"copy": "/api/v2/credentials/9/copy/",
"input_sources": "/api/v2/credentials/9/input_sources/",
"credential_type": "/api/v2/credential_types/10/"
},
"summary_fields": {
"organization": {
"id": 4,
"name": "Default",
"description": ""
},
"credential_type": {
"id": 10,
"name": "Google Compute Engine",
"description": ""
},
"created_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"modified_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"object_roles": {
"admin_role": {
"description": "Can manage all aspects of the credential",
"name": "Admin",
"id": 287
},
"use_role": {
"description": "Can use the credential in a job template",
"name": "Use",
"id": 288
},
"read_role": {
"description": "May view settings for the credential",
"name": "Read",
"id": 289
}
},
"user_capabilities": {
"edit": true,
"delete": true,
"copy": true,
"use": true
},
"owners": [
{
"id": 1,
"type": "user",
"name": "admin",
"description": " ",
"url": "/api/v2/users/1/"
},
{
"id": 4,
"type": "organization",
"name": "Default",
"description": "",
"url": "/api/v2/organizations/4/"
}
]
},
"created": "2020-04-13T17:33:27.625773Z",
"modified": "2020-04-13T17:33:27.625882Z",
"name": "a gce cred",
"description": "",
"organization": 4,
"credential_type": 10,
"inputs": {
"project": "test123",
"username": "test123.iam.gserviceaccount.com",
"ssh_key_data": "$encrypted$"
},
"kind": "gce",
"cloud": true,
"kubernetes": false
}

View File

@@ -0,0 +1,92 @@
{
"id": 3,
"type": "credential",
"url": "/api/v2/credentials/3/",
"related": {
"named_url": "/api/v2/credentials/oersdgfasf++Machine+ssh++org/",
"created_by": "/api/v2/users/1/",
"modified_by": "/api/v2/users/1/",
"organization": "/api/v2/organizations/1/",
"activity_stream": "/api/v2/credentials/3/activity_stream/",
"access_list": "/api/v2/credentials/3/access_list/",
"object_roles": "/api/v2/credentials/3/object_roles/",
"owner_users": "/api/v2/credentials/3/owner_users/",
"owner_teams": "/api/v2/credentials/3/owner_teams/",
"copy": "/api/v2/credentials/3/copy/",
"input_sources": "/api/v2/credentials/3/input_sources/",
"credential_type": "/api/v2/credential_types/1/"
},
"summary_fields": {
"organization": {
"id": 1,
"name": "org",
"description": ""
},
"credential_type": {
"id": 1,
"name": "Machine",
"description": ""
},
"created_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"modified_by": {
"id": 1,
"username": "admin",
"first_name": "",
"last_name": ""
},
"object_roles": {
"admin_role": {
"description": "Can manage all aspects of the credential",
"name": "Admin",
"id": 36
},
"use_role": {
"description": "Can use the credential in a job template",
"name": "Use",
"id": 37
},
"read_role": {
"description": "May view settings for the credential",
"name": "Read",
"id": 38
}
},
"user_capabilities": {
"edit": true,
"delete": true,
"copy": true,
"use": true
},
"owners": [
{
"id": 1,
"type": "user",
"name": "admin",
"description": " ",
"url": "/api/v2/users/1/"
},
{
"id": 1,
"type": "organization",
"name": "org",
"description": "",
"url": "/api/v2/organizations/1/"
}
]
},
"created": "2020-02-18T15:35:04.563928Z",
"modified": "2020-02-18T15:35:04.563957Z",
"name": "oersdgfasf",
"description": "",
"organization": 1,
"credential_type": 1,
"inputs": {},
"kind": "ssh",
"cloud": false,
"kubernetes": false
}