Skip to content

Commit

Permalink
Adjust tests for signed VersionInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Billing committed Oct 1, 2020
1 parent ca5c761 commit 575bdb2
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
64 changes: 60 additions & 4 deletions tnoodle-ui/src/test/VersionInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import store from "../main/redux/Store";

import VersionInfo from "../main/components/VersionInfo";

import { scrambleProgram, version } from "./mock/wca.api.mock";

const tnoodleApi = require("../main/api/tnoodle.api");
const wcaApi = require("../main/api/wca.api");

Expand Down Expand Up @@ -45,6 +43,7 @@ it("Current version is the correct one", async () => {
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-2.jar",
},
allowed: ["TNoodle-WCA-2"],
publicKeyBytes: "key",
history: ["TNoodle-WCA-0", "TNoodle-WCA-1", "TNoodle-WCA-2"],
};

Expand Down Expand Up @@ -93,6 +92,7 @@ it("Current version is allowed, but it's not the latest one", async () => {
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-3.jar",
},
allowed: ["TNoodle-WCA-2", "TNoodle-WCA-3"],
publicKeyBytes: "key",
history: [
"TNoodle-WCA-0",
"TNoodle-WCA-1",
Expand Down Expand Up @@ -131,7 +131,7 @@ it("Current version is allowed, but it's not the latest one", async () => {
wcaApi.fetchVersionInfo.mockRestore();
});

it("Not official version alert", async () => {
it("Not signed version alert", async () => {
const version = {
projectName: "TNoodle-WCA",
projectVersion: "3",
Expand All @@ -148,6 +148,60 @@ it("Not official version alert", async () => {
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-3.jar",
},
allowed: ["TNoodle-WCA-3"],
publicKeyBytes: "key",
history: [
"TNoodle-WCA-0",
"TNoodle-WCA-1",
"TNoodle-WCA-2",
"TNoodle-WCA-3",
],
};

jest.spyOn(tnoodleApi, "fetchRunningVersion").mockImplementation(() =>
Promise.resolve(version)
);

jest.spyOn(wcaApi, "fetchVersionInfo").mockImplementation(() =>
Promise.resolve(scrambleProgram)
);

await act(async () => {
render(
<Provider store={store}>
<VersionInfo />
</Provider>,
container
);
});

// The warning should be "do not use this"
const alert = container.querySelector(".alert-danger");
expect(alert.textContent).toContain(
"This TNoodle version is not signed."
);

tnoodleApi.fetchRunningVersion.mockRestore();
wcaApi.fetchVersionInfo.mockRestore();
});

it("Signed with different key", async () => {
const version = {
projectName: "TNoodle-WCA",
projectVersion: "3",
signedBuild: true,
signatureKeyBytes: "fooBar", // This should trigger an alert, even with currentVersion == runningVersion
};

const scrambleProgram = {
current: {
name: "TNoodle-WCA-3",
information:
"https://www.worldcubeassociation.org/regulations/scrambles/",
download:
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-3.jar",
},
allowed: ["TNoodle-WCA-3"],
publicKeyBytes: "key",
history: [
"TNoodle-WCA-0",
"TNoodle-WCA-1",
Expand Down Expand Up @@ -176,7 +230,7 @@ it("Not official version alert", async () => {
// The warning should be "do not use this"
const alert = container.querySelector(".alert-danger");
expect(alert.textContent).toContain(
"This TNoodle version is not official and scrambles generated with this must not be used in competition."
"This TNoodle version is not signed."
);

tnoodleApi.fetchRunningVersion.mockRestore();
Expand All @@ -200,6 +254,7 @@ it("Not allowed TNoodle version, despite it's official", async () => {
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-3.jar",
},
allowed: ["TNoodle-WCA-2", "TNoodle-WCA-3"],
publicKeyBytes: "key",
history: [
"TNoodle-WCA-0",
"TNoodle-WCA-1",
Expand Down Expand Up @@ -245,6 +300,7 @@ it("Do not bother the user if we can't be sure", async () => {
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-3.jar",
},
allowed: ["TNoodle-WCA-2", "TNoodle-WCA-3"],
publicKeyBytes: "key",
history: [
"TNoodle-WCA-0",
"TNoodle-WCA-1",
Expand Down
1 change: 1 addition & 0 deletions tnoodle-ui/src/test/mock/wca.api.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const scrambleProgram = {
"https://www.worldcubeassociation.org/regulations/scrambles/tnoodle/TNoodle-WCA-2.jar",
},
allowed: ["TNoodle-WCA-2"],
publicKeyBytes: "key",
history: ["TNoodle-WCA-0", "TNoodle-WCA-1", "TNoodle-WCA-2"],
};

Expand Down

0 comments on commit 575bdb2

Please sign in to comment.