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 explicit scope to the new repo form #5240

Merged
merged 1 commit into from
Aug 30, 2022
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
212 changes: 83 additions & 129 deletions dashboard/src/actions/repos.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ const pkgRepoFormData = {
cert: "",
key: "",
},
namespace: "my-namespace",
isNamespaceScoped: true,
} as IPkgRepoFormData;

const actionTestCases: ITestCase[] = [
Expand Down Expand Up @@ -416,30 +418,25 @@ describe("fetchRepoSummaries", () => {
});

describe("addRepo", () => {
const addRepoCMD = repoActions.addRepo("my-namespace", pkgRepoFormData);
const addRepoCMD = repoActions.addRepo(pkgRepoFormData);

context("when authHeader provided", () => {
const addRepoCMDAuth = repoActions.addRepo("my-namespace", {
const addRepoCMDAuth = repoActions.addRepo({
...pkgRepoFormData,
authHeader: "Bearer: abc",
});

it("calls PackageRepositoriesService create including a auth struct (authHeader)", async () => {
await store.dispatch(addRepoCMDAuth);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
authHeader: "Bearer: abc",
},
true,
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
authHeader: "Bearer: abc",
});
});

it("calls PackageRepositoriesService create including ociRepositories", async () => {
await store.dispatch(
repoActions.addRepo("my-namespace", {
repoActions.addRepo({
...pkgRepoFormData,
type: RepositoryStorageTypes.PACKAGE_REPOSITORY_STORAGE_OCI,
customDetail: {
Expand All @@ -448,34 +445,23 @@ describe("addRepo", () => {
},
}),
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
type: RepositoryStorageTypes.PACKAGE_REPOSITORY_STORAGE_OCI,
customDetail: {
...pkgRepoFormData.customDetail,
ociRepositories: ["apache", "jenkins"],
},
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,

type: RepositoryStorageTypes.PACKAGE_REPOSITORY_STORAGE_OCI,
customDetail: {
...pkgRepoFormData.customDetail,
ociRepositories: ["apache", "jenkins"],
},
true,
);
});
});

it("calls PackageRepositoriesService create skipping TLS verification", async () => {
await store.dispatch(
repoActions.addRepo("my-namespace", { ...pkgRepoFormData, skipTLS: true }),
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
skipTLS: true,
},
true,
);
await store.dispatch(repoActions.addRepo({ ...pkgRepoFormData, skipTLS: true }));
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
skipTLS: true,
});
});

it("returns true", async () => {
Expand All @@ -485,22 +471,17 @@ describe("addRepo", () => {
});

context("when a customCA is provided", () => {
const addRepoCMDAuth = repoActions.addRepo("my-namespace", {
const addRepoCMDAuth = repoActions.addRepo({
...pkgRepoFormData,
customCA: "This is a cert!",
});

it("calls PackageRepositoriesService create including a auth struct (custom CA)", async () => {
await store.dispatch(addRepoCMDAuth);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
customCA: "This is a cert!",
},
true,
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
customCA: "This is a cert!",
});
});

it("returns true (addRepoCMDAuth)", async () => {
Expand All @@ -510,38 +491,36 @@ describe("addRepo", () => {

it("sets flux repos as global", async () => {
await store.dispatch(
repoActions.addRepo("my-namespace", {
repoActions.addRepo({
...pkgRepoFormData,
namespace: "my-namespace",
isNamespaceScoped: false,
plugin: fluxPlugin as Plugin,
}),
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
plugin: fluxPlugin,
},
false,
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
namespace: "my-namespace",
isNamespaceScoped: false,
plugin: fluxPlugin,
});
});

it("sets carvel repos as global if using the carvelGlobalNamespace", async () => {
await store.dispatch(
repoActions.addRepo(carvelGlobalNamespace, {
repoActions.addRepo({
...pkgRepoFormData,
namespace: carvelGlobalNamespace,
isNamespaceScoped: false,
plugin: carvelPlugin as Plugin,
}),
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
carvelGlobalNamespace,
{
...pkgRepoFormData,
plugin: carvelPlugin,
},
false,
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
namespace: carvelGlobalNamespace,
isNamespaceScoped: false,
plugin: carvelPlugin,
});
});
});

Expand All @@ -550,9 +529,7 @@ describe("addRepo", () => {
await store.dispatch(addRepoCMD);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
pkgRepoFormData,
true,
);
});

Expand Down Expand Up @@ -607,7 +584,7 @@ describe("addRepo", () => {

it("includes registry secrets if given", async () => {
await store.dispatch(
repoActions.addRepo("my-namespace", {
repoActions.addRepo({
...pkgRepoFormData,
customDetail: {
...pkgRepoFormData.customDetail,
Expand All @@ -619,39 +596,29 @@ describe("addRepo", () => {
}),
);

expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
customDetail: {
...pkgRepoFormData.customDetail,
imagesPullSecret: {
secretRef: "repo-1",
credentials: { server: "", username: "", password: "", email: "" },
},
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
customDetail: {
...pkgRepoFormData.customDetail,
imagesPullSecret: {
secretRef: "repo-1",
credentials: { server: "", username: "", password: "", email: "" },
},
},
true,
);
});
});

it("calls PackageRepositoriesService create with description", async () => {
await store.dispatch(
repoActions.addRepo("my-namespace", {
repoActions.addRepo({
...pkgRepoFormData,
description: "This is a weird description 123!@#$%^&&*()_+-=<>?/.,;:'\"",
}),
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
description: "This is a weird description 123!@#$%^&&*()_+-=<>?/.,;:'\"",
},
true,
);
expect(PackageRepositoriesService.addPackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
description: "This is a weird description 123!@#$%^&&*()_+-=<>?/.,;:'\"",
});
});
});

Expand Down Expand Up @@ -681,21 +648,17 @@ describe("updateRepo", () => {
];

await store.dispatch(
repoActions.updateRepo("my-namespace", {
repoActions.updateRepo({
...pkgRepoFormData,
authHeader: "foo",
}),
);

expect(store.getActions()).toEqual(expectedActions);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
authHeader: "foo",
},
);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
authHeader: "foo",
});
});

it("updates a repo with an customCA", async () => {
Expand Down Expand Up @@ -724,17 +687,16 @@ describe("updateRepo", () => {
];

await store.dispatch(
repoActions.updateRepo("my-namespace", { ...pkgRepoFormData, customCA: "This is a cert!" }),
);
expect(store.getActions()).toEqual(expectedActions);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
repoActions.updateRepo({
...pkgRepoFormData,
customCA: "This is a cert!",
},
}),
);
expect(store.getActions()).toEqual(expectedActions);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
customCA: "This is a cert!",
});
});

it("returns an error if failed", async () => {
Expand All @@ -751,7 +713,7 @@ describe("updateRepo", () => {
},
];

await store.dispatch(repoActions.updateRepo("my-namespace", pkgRepoFormData));
await store.dispatch(repoActions.updateRepo(pkgRepoFormData));
expect(store.getActions()).toEqual(expectedActions);
});

Expand All @@ -760,41 +722,33 @@ describe("updateRepo", () => {
packageRepoRef: packageRepositoryDetail.packageRepoRef,
} as UpdatePackageRepositoryResponse);
await store.dispatch(
repoActions.updateRepo("my-namespace", {
repoActions.updateRepo({
...pkgRepoFormData,
type: RepositoryStorageTypes.PACKAGE_REPOSITORY_STORAGE_OCI,
customDetail: { ...pkgRepoFormData.customDetail, ociRepositories: ["apache", "jenkins"] },
}),
);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
type: RepositoryStorageTypes.PACKAGE_REPOSITORY_STORAGE_OCI,
customDetail: { ...pkgRepoFormData.customDetail, ociRepositories: ["apache", "jenkins"] },
},
);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
type: RepositoryStorageTypes.PACKAGE_REPOSITORY_STORAGE_OCI,
customDetail: { ...pkgRepoFormData.customDetail, ociRepositories: ["apache", "jenkins"] },
});
});

it("updates a repo with description", async () => {
PackageRepositoriesService.updatePackageRepository = jest.fn().mockReturnValue({
packageRepoRef: packageRepositoryDetail.packageRepoRef,
} as UpdatePackageRepositoryResponse);
await store.dispatch(
repoActions.updateRepo("my-namespace", {
repoActions.updateRepo({
...pkgRepoFormData,
description: "updated description",
}),
);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith(
"default",
"my-namespace",
{
...pkgRepoFormData,
description: "updated description",
},
);
expect(PackageRepositoriesService.updatePackageRepository).toHaveBeenCalledWith("default", {
...pkgRepoFormData,
description: "updated description",
});
});
});

Expand Down
Loading