Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cypress tests to MR secure DB section #3631

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions frontend/src/__mocks__/mockModelRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ type MockModelRegistryType = {
name?: string;
namespace?: string;
conditions?: K8sCondition[];
sslRootCertificateConfigMap?: { name: string; key: string } | null;
sslRootCertificateSecret?: { name: string; key: string } | null;
};

export const mockModelRegistry = ({
Expand All @@ -25,37 +27,47 @@ export const mockModelRegistry = ({
type: 'Available',
},
],
}: MockModelRegistryType): ModelRegistryKind => ({
apiVersion: 'modelregistry.opendatahub.io/v1alpha1',
kind: 'ModelRegistry',
metadata: {
name,
creationTimestamp: '2024-03-14T08:01:42Z',
namespace,
},
spec: {
grpc: {},
rest: {},
istio: {
gateway: {
grpc: { tls: {} },
rest: { tls: {} },
},
sslRootCertificateConfigMap = null,
sslRootCertificateSecret = null,
}: MockModelRegistryType): ModelRegistryKind => {
const data: ModelRegistryKind = {
apiVersion: 'modelregistry.opendatahub.io/v1alpha1',
kind: 'ModelRegistry',
metadata: {
name,
creationTimestamp: '2024-03-14T08:01:42Z',
namespace,
},
postgres: {
database: 'model-registry',
host: 'model-registry-db',
passwordSecret: {
key: 'database-password',
name: 'model-registry-db',
spec: {
grpc: {},
rest: {},
istio: {
gateway: {
grpc: { tls: {} },
rest: { tls: {} },
},
},
mysql: {
database: 'model-registry',
host: 'model-registry-db',
passwordSecret: {
key: 'database-password',
name: 'model-registry-db',
},
port: 5432,
skipDBCreation: false,
username: 'mlmduser',
},
port: 5432,
skipDBCreation: false,
sslMode: 'disable',
username: 'mlmduser',
},
},
status: {
conditions,
},
});
status: {
conditions,
},
};

if (sslRootCertificateConfigMap && data.spec.mysql) {
data.spec.mysql.sslRootCertificateConfigMap = sslRootCertificateConfigMap;
} else if (sslRootCertificateSecret && data.spec.mysql) {
data.spec.mysql.sslRootCertificateSecret = sslRootCertificateSecret;
}
return data;
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { appChrome } from './appChrome';
import { Contextual } from './components/Contextual';
import { K8sNameDescriptionField } from './components/subComponents/K8sNameDescriptionField';
import { SearchSelector } from './components/subComponents/SearchSelector';

export enum FormFieldSelector {
NAME = '#mr-name',
Expand Down Expand Up @@ -29,6 +31,10 @@ export enum DatabaseDetailsTestId {
class ModelRegistrySettings {
k8sNameDescription = new K8sNameDescriptionField('mr');

resourceNameSelect = new SearchSelector('existing-ca-resource-selector');

keySelect = new SearchSelector('existing-ca-key-selector');

visit(wait = true) {
cy.visitWithLogin('/modelRegistrySettings');
if (wait) {
Expand Down Expand Up @@ -130,6 +136,10 @@ class ModelRegistrySettings {
return cy.findByTestId('existing-ca-radio');
}

findUploadNewCertificateRadio() {
return cy.findByTestId('new-certificate-ca-radio');
}

findAddSecureDbMRCheckbox() {
return cy.findByTestId('add-secure-db-mr-checkbox');
}
Expand All @@ -141,6 +151,32 @@ class ModelRegistrySettings {
findExistingCAKeyInputToggle() {
return cy.findByTestId('existing-ca-key-selector-toggle');
}

getNewCertificateUpload() {
return new CertificateUpload(() => cy.findByTestId('certificate-upload'));
}

findErrorFetchingResourceAlert() {
return cy.findByTestId('error-fetching-resource-alert');
}

findCertificateNote() {
return cy.findByTestId('certificate-note');
}
}

class CertificateUpload extends Contextual<HTMLElement> {
findUploadCertificateInput() {
return this.find().find('[data-testid="new-certificate-upload"] input[type="file"]');
}

uploadPemFile(filePath: string) {
this.findUploadCertificateInput().selectFile([filePath], { force: true });
}

findRestrictedFileUploadHelptext() {
return cy.findByTestId('restricted-file-example-helpText');
}
}

export const modelRegistrySettings = new ModelRegistrySettings();
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ declare global {
type: 'GET /api/modelRegistries',
response: OdhResponse<K8sResourceListResult<ModelRegistryKind>>,
) => Cypress.Chainable<null>) &
((
type: 'POST /api/modelRegistries',
response: OdhResponse<ModelRegistryKind>,
) => Cypress.Chainable<null>) &
((
type: 'PATCH /api/modelRegistries/:modelRegistryName',
options: {
Expand Down Expand Up @@ -656,7 +660,7 @@ declare global {
) => Cypress.Chainable<null>) &
((
type: 'GET /api/modelRegistryCertificates',
response: ListConfigSecretsResponse,
response: OdhResponse<ListConfigSecretsResponse>,
) => Cypress.Chainable<null>) &
((
type: 'POST /api/connection-types',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sample certificate
Loading
Loading