Skip to content

Commit

Permalink
[web] Show TPM reminder only if encryption was set
Browse files Browse the repository at this point in the history
It does not make sense to display the reminder when the product has set
the TPM encryption method by default but the user did not set the
encryption.
  • Loading branch information
dgdavid committed Jan 16, 2024
1 parent 8170cc9 commit e019337
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
4 changes: 2 additions & 2 deletions web/src/components/core/InstallationFinished.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ function InstallationFinished() {
const iguana = await client.manager.useIguana();
// FIXME: This logic should likely not be placed here, it's too coupled to storage internals.
// Something to fix when this whole page is refactored in a (hopefully near) future.
const { settings: { encryptionMethod } } = await client.storage.proposal.getResult();
const { settings: { encryptionPassword, encryptionMethod } } = await client.storage.proposal.getResult();
setUsingIguana(iguana);
setUsingTpm(encryptionMethod === EncryptionMethods.TPM);
setUsingTpm(encryptionPassword?.length && encryptionMethod === EncryptionMethods.TPM);
}

// TODO: display the page in a loading mode while needed data is being fetched.
Expand Down
47 changes: 38 additions & 9 deletions web/src/components/core/InstallationFinished.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ jest.mock("~/client");
jest.mock("~/components/core/Sidebar", () => () => <div>Agama sidebar</div>);

const finishInstallationFn = jest.fn();
let encryptionPassword;
let encryptionMethod;

describe("InstallationFinished", () => {
beforeEach(() => {
encryptionPassword = "n0tS3cr3t";
encryptionMethod = EncryptionMethods.LUKS2;
createClient.mockImplementation(() => {
return {
Expand All @@ -45,7 +47,9 @@ describe("InstallationFinished", () => {
},
storage: {
proposal: {
getResult: jest.fn().mockResolvedValue({ settings: { encryptionMethod } })
getResult: jest.fn().mockResolvedValue({
settings: { encryptionMethod, encryptionPassword }
})
},
}
};
Expand All @@ -69,21 +73,46 @@ describe("InstallationFinished", () => {
expect(finishInstallationFn).toHaveBeenCalled();
});

describe("when TPM was set to decrypt automatically on each boot", () => {
describe("when TPM is set as encryption method", () => {
beforeEach(() => {
encryptionMethod = EncryptionMethods.TPM;
});

it("shows the TPM reminder", async () => {
installerRender(<InstallationFinished />);
await screen.findAllByText(/TPM/);
describe("and encryption was set", () => {
it("shows the TPM reminder", async () => {
installerRender(<InstallationFinished />);
await screen.findAllByText(/TPM/);
});
});

describe("but encryption was not set", () => {
beforeEach(() => {
encryptionPassword = "";
});

it("does not show the TPM reminder", async () => {
const { user } = installerRender(<InstallationFinished />);
// Forcing the test to slow down a bit with a fake user interaction
// because actually the reminder will be not rendered immediately
// making the queryAllByText to produce a false positive if triggered
// too early here.
const congratsText = screen.getByText("Congratulations!");
await user.click(congratsText);
expect(screen.queryAllByText(/TPM/)).toHaveLength(0);
});
});
});

describe("when TPM was not set to decrypt automatically on each boot", () => {
it("does not show the TPM reminder", () => {
installerRender(<InstallationFinished />);
expect(screen.queryByText(/TPM/)).toBeNull();
describe("when TPM is not set as encryption method", () => {
it("does not show the TPM reminder", async () => {
const { user } = installerRender(<InstallationFinished />);
// Forcing the test to slow down a bit with a fake user interaction
// because actually the reminder will be not rendered immediately
// making the queryAllByText to produce a false positive if triggered
// too early here.
const congratsText = screen.getByText("Congratulations!");
await user.click(congratsText);
expect(screen.queryAllByText(/TPM/)).toHaveLength(0);
});
});
});

0 comments on commit e019337

Please sign in to comment.