Skip to content

Commit

Permalink
Merge pull request rancher#10563 from momesgin/10456-create-repo-auth
Browse files Browse the repository at this point in the history
Fix Creating Repository with Secret
  • Loading branch information
momesgin authored Mar 11, 2024
2 parents b0d2dcb + 835ca5c commit dfcd10a
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 17 deletions.
24 changes: 16 additions & 8 deletions cypress/e2e/po/components/select-or-create-auth.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,31 @@ export default class SelectOrCreateAuthPo extends ComponentPo {
return new LabeledSelectPo(`${ this.selector } [data-testid="auth-secret-select"]`, this.self());
}

setAuthSecret(secretType: string, username: string, password: string) {
const privateKey = new LabeledInputPo(`${ this.selector } [data-testid="auth-secret-${ secretType }-private-key"]`, this.self());
const publicKey = new LabeledInputPo(`${ this.selector } [data-testid="auth-secret-${ secretType }-public-key"]`, this.self());
setBasicAuthSecret(username: string, password: string) {
const usernameInput = new LabeledInputPo(`${ this.selector } [data-testid="auth-secret-basic-username"]`, this.self());
const passwordInput = new LabeledInputPo(`${ this.selector } [data-testid="auth-secret-basic-password"]`, this.self());

privateKey.set(username);
publicKey.set(password);
usernameInput.set(username);
passwordInput.set(password);
}

setSSHSecret(privateKey: string, publicKey: string) {
const privateKeyInput = new LabeledInputPo(`${ this.selector } [data-testid="auth-secret-ssh-private-key"]`, this.self());
const publicKeyInput = new LabeledInputPo(`${ this.selector } [data-testid="auth-secret-ssh-public-key"]`, this.self());

privateKeyInput.set(privateKey);
publicKeyInput.set(publicKey);
}

createBasicAuth(username = 'auth-test-user', password = 'auth-test-password') {
this.authSelect().toggle();
this.authSelect().clickOptionWithLabel('Create a HTTP Basic Auth Secret');
this.setAuthSecret('basic', username, password);
this.setBasicAuthSecret(username, password);
}

createSSHAuth(privateKey: string, publicKey: string) {
this.authSelect().toggle();
this.authSelect().clickOptionWithLabel('Create a SSH Auth Secret');
this.setAuthSecret('ssh', privateKey, publicKey);
this.authSelect().clickOptionWithLabel('Create a SSH Key Secret');
this.setSSHSecret(privateKey, publicKey);
}
}
9 changes: 9 additions & 0 deletions cypress/e2e/po/edit/chart-repositories.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AsyncButtonPo from '@/cypress/e2e/po/components/async-button.po';
import LabeledSelectPo from '@/cypress/e2e/po/components/labeled-select.po';
import RadioGroupInputPo from '@/cypress/e2e/po/components/radio-group-input.po';
import NameNsDescription from '@/cypress/e2e/po/components/name-ns-description.po';
import SelectOrCreateAuthPo from '@/cypress/e2e/po/components/select-or-create-auth.po';

export default class ChartRepositoriesCreateEditPo extends PagePo {
private static createPath(clusterId: string, product: 'apps' | 'manager', repoName?: string ) {
Expand Down Expand Up @@ -44,6 +45,14 @@ export default class ChartRepositoriesCreateEditPo extends PagePo {
return new AsyncButtonPo('[data-testid="action-button-async-button"]', this.self());
}

authSelectOrCreate(selector: string) {
return new SelectOrCreateAuthPo(selector);
}

clusterrepoAuthSelectOrCreate() {
return this.authSelectOrCreate('[data-testid="clusterrepo-auth-secret"]');
}

saveAndWaitForRequests(method: string, url: string) {
cy.intercept(method, url).as('request');
this.saveCreateForm().click();
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/po/pages/global-settings/home-links.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class HomeLinksPagePo extends RootClusterPage {
}

urlInput(): LabeledInputPo {
return new LabeledInputPo('[data-testid="text-area-auto-grow"]');
return new LabeledInputPo('[data-testid="value-multiline"]');
}

applyButton() {
Expand Down
64 changes: 64 additions & 0 deletions cypress/e2e/tests/pages/manager/repositories.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,68 @@ describe('Cluster Management Helm Repositories', { testIsolation: 'off', tags: [
// check list details
cy.contains(this.repoName).should('not.exist');
});

it('can create a repository with basic auth', function() {
ChartRepositoriesPagePo.navTo();
repositoriesPage.waitForPage();
repositoriesPage.waitForGoTo('/v1/catalog.cattle.io.clusterrepos?exclude=metadata.managedFields');
repositoriesPage.create();
repositoriesPage.createEditRepositories().waitForPage();
repositoriesPage.createEditRepositories().nameNsDescription().name().set(this.repoName);
repositoriesPage.createEditRepositories().nameNsDescription().description().set(`${ this.repoName }-description`);
repositoriesPage.createEditRepositories().repoRadioBtn().set(1);
repositoriesPage.createEditRepositories().gitRepoUrl().set('https://git.rancher.io/charts');
repositoriesPage.createEditRepositories().gitBranch().set('release-v2.8');
repositoriesPage.createEditRepositories().clusterrepoAuthSelectOrCreate().createBasicAuth('test', 'test');
repositoriesPage.createEditRepositories().saveAndWaitForRequests('POST', '/v1/catalog.cattle.io.clusterrepos');
repositoriesPage.waitForPage();

// check list details
repositoriesPage.list().details(this.repoName, 2).should('be.visible');
repositoriesPage.list().details(this.repoName, 1).contains('In Progress').should('be.visible');
repositoriesPage.list().actionMenu(this.repoName).getMenuItem('Delete').click();

const promptRemove = new PromptRemove();

cy.intercept('DELETE', `v1/catalog.cattle.io.clusterrepos/${ this.repoName }`).as('deleteRepository');

promptRemove.remove();
cy.wait('@deleteRepository');
repositoriesPage.waitForPage();

// check list details
cy.contains(this.repoName).should('not.exist');
});

it('can create a repository with SSH key', function() {
ChartRepositoriesPagePo.navTo();
repositoriesPage.waitForPage();
repositoriesPage.waitForGoTo('/v1/catalog.cattle.io.clusterrepos?exclude=metadata.managedFields');
repositoriesPage.create();
repositoriesPage.createEditRepositories().waitForPage();
repositoriesPage.createEditRepositories().nameNsDescription().name().set(this.repoName);
repositoriesPage.createEditRepositories().nameNsDescription().description().set(`${ this.repoName }-description`);
repositoriesPage.createEditRepositories().repoRadioBtn().set(1);
repositoriesPage.createEditRepositories().gitRepoUrl().set('https://git.rancher.io/charts');
repositoriesPage.createEditRepositories().gitBranch().set('release-v2.8');
repositoriesPage.createEditRepositories().clusterrepoAuthSelectOrCreate().createSSHAuth('privateKey', 'publicKey');
repositoriesPage.createEditRepositories().saveAndWaitForRequests('POST', '/v1/catalog.cattle.io.clusterrepos');
repositoriesPage.waitForPage();

// check list details
repositoriesPage.list().details(this.repoName, 2).should('be.visible');

repositoriesPage.list().actionMenu(this.repoName).getMenuItem('Delete').click();

const promptRemove = new PromptRemove();

cy.intercept('DELETE', `v1/catalog.cattle.io.clusterrepos/${ this.repoName }`).as('deleteRepository');

promptRemove.remove();
cy.wait('@deleteRepository');
repositoriesPage.waitForPage();

// check list details
cy.contains(this.repoName).should('not.exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export default Vue.extend({
<template>
<textarea
ref="ta"
data-testid="text-area-auto-grow"
:data-testid="$attrs['data-testid'] ? $attrs['data-testid'] : 'text-area-auto-grow'"
:disabled="isDisabled"
:style="style"
:placeholder="placeholder"
Expand Down
8 changes: 4 additions & 4 deletions shell/components/form/SelectOrCreateAuthSecret.vue
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default {
types.push(SECRET_TYPES.RKE_AUTH_CONFIG);
}
const out = this.allSecrets
let out = this.allSecrets
.filter((x) => this.namespace && this.limitToNamespace ? x.metadata.namespace === this.namespace : true)
.filter((x) => {
// Must match one of the types if given
Expand Down Expand Up @@ -254,7 +254,7 @@ export default {
}
if ( !this.limitToNamespace ) {
sortBy(out, 'group');
out = sortBy(out, 'group');
if ( out.length ) {
let lastGroup = '';
Expand Down Expand Up @@ -509,15 +509,15 @@ export default {
<div :class="moreCols">
<LabeledInput
v-model="publicKey"
data-testid="auth-secret-basic-public-key"
data-testid="auth-secret-basic-username"
:mode="mode"
label-key="selectOrCreateAuthSecret.basic.username"
/>
</div>
<div :class="moreCols">
<LabeledInput
v-model="privateKey"
data-testid="auth-secret-basic-private-key"
data-testid="auth-secret-basic-password"
:mode="mode"
type="password"
label-key="selectOrCreateAuthSecret.basic.password"
Expand Down
2 changes: 1 addition & 1 deletion shell/components/form/__tests__/KeyValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('component: KeyValue', () => {
stubs: { CodeMirror: true }
});

const inputFieldTextArea = wrapper.find('[data-testid="text-area-auto-grow"]');
const inputFieldTextArea = wrapper.find('[data-testid="value-multiline"]');

inputFieldTextArea.setValue('bar\n');

Expand Down
9 changes: 7 additions & 2 deletions shell/edit/catalog.cattle.io.clusterrepo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RadioGroup } from '@components/Form/Radio';
import NameNsDescription from '@shell/components/form/NameNsDescription';
import Labels from '@shell/components/form/Labels';
import SelectOrCreateAuthSecret from '@shell/components/form/SelectOrCreateAuthSecret';
import { NAMESPACE } from '@shell/config/types';
import { MANAGEMENT, NAMESPACE } from '@shell/config/types';
export default {
name: 'CruCatalogRepo',
Expand All @@ -28,6 +28,9 @@ export default {
},
computed: {
inStore() {
return this.$store.getters['currentProduct']?.inStore || MANAGEMENT;
},
secretNamespace() {
const tryNames = ['cattle-system', 'default'];
Expand All @@ -37,7 +40,7 @@ export default {
}
}
return this.$store.getters['cluster/all'](NAMESPACE)[0]?.id;
return this.$store.getters[`${ this.inStore }/all`](NAMESPACE)[0]?.id;
}
},
Expand Down Expand Up @@ -119,9 +122,11 @@ export default {
<SelectOrCreateAuthSecret
v-model="value.spec.clientSecret"
data-testid="clusterrepo-auth-secret"
:register-before-hook="registerBeforeHook"
:namespace="secretNamespace"
:limit-to-namespace="false"
:in-store="inStore"
generate-name="clusterrepo-auth-"
/>
Expand Down

0 comments on commit dfcd10a

Please sign in to comment.