Skip to content

Commit 2df8a75

Browse files
committed
test(e2e): add tests for crypto operations
1 parent 7c646d0 commit 2df8a75

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

cypress/e2e/encryptDecrypt.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Encryption & Decryption Flow', () => {
4+
it('encrypts and then decrypts a message end-to-end', () => {
5+
// Generate a key pair first
6+
cy.visit('/');
7+
cy.get('#gen-name').type('E2E User');
8+
cy.get('#gen-email').type('e2e@example.com');
9+
cy.get('#form-keygen button[type="submit"]').click();
10+
cy.get('#output-keygen', { timeout: 60000 })
11+
.should('not.be.empty')
12+
.invoke('text')
13+
.then((keyText) => {
14+
const [publicKey, privateKey] = keyText.split('\n\n');
15+
16+
// Encrypt a message
17+
cy.get('#encrypt-message').type('Hello Cypress');
18+
cy.get('#encrypt-pubkey').type(publicKey);
19+
cy.get('#form-encrypt button[type="submit"]').click();
20+
cy.get('#output-encrypt', { timeout: 60000 })
21+
.should('not.be.empty')
22+
.invoke('text')
23+
.then((encrypted) => {
24+
25+
// Decrypt the message
26+
cy.get('#decrypt-message').clear().type(encrypted);
27+
cy.get('#decrypt-privkey').type(privateKey);
28+
cy.get('#form-decrypt button[type="submit"]').click();
29+
cy.get('#output-decrypt', { timeout: 60000 })
30+
.should('contain', 'Hello Cypress');
31+
});
32+
});
33+
});
34+
});

cypress/e2e/importManage.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Import & Manage Keys Flow', () => {
4+
it('imports a key, searches it, and deletes it', () => {
5+
// Generate a key pair to import
6+
cy.visit('/');
7+
cy.get('#gen-name').type('ImportUser');
8+
cy.get('#gen-email').type('import@example.com');
9+
cy.get('#form-keygen button[type="submit"]').click();
10+
cy.get('#output-keygen', { timeout: 60000 })
11+
.invoke('text')
12+
.then((keyText) => {
13+
const [publicKey] = keyText.split('\n\n');
14+
15+
// Navigate to Keybox (import)
16+
cy.get('#nav-import').click();
17+
18+
// Import public key
19+
cy.get('#import-key').type(publicKey);
20+
cy.get('#form-import button[type="submit"]').click();
21+
cy.get('.toast').should('contain', 'Imported public key');
22+
23+
// Search for the imported key
24+
cy.get('#key-search').type('public');
25+
cy.get('#key-list').should('contain', 'Public Key');
26+
27+
// Delete the key
28+
cy.get('.key-item .danger').click();
29+
cy.on('window:confirm', () => true);
30+
cy.get('.toast').should('contain', 'Key deleted');
31+
cy.get('#key-list').should('not.contain', 'Public Key');
32+
});
33+
});
34+
});

cypress/e2e/signVerify.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Sign & Verify Flow', () => {
4+
it('signs a message and then verifies the signature', () => {
5+
cy.visit('/');
6+
// Generate a key pair
7+
cy.get('#gen-name').type('Signer User');
8+
cy.get('#gen-email').type('signer@example.com');
9+
cy.get('#form-keygen button[type="submit"]').click();
10+
cy.get('#output-keygen', { timeout: 60000 })
11+
.should('not.be.empty')
12+
.invoke('text')
13+
.then((keyText) => {
14+
const [publicKey, privateKey] = keyText.split('\n\n');
15+
16+
// Sign a message
17+
cy.get('#sign-message').type('Message to Sign');
18+
cy.get('#sign-privkey').type(privateKey);
19+
cy.get('#form-sign button[type="submit"]').click();
20+
cy.get('#output-sign', { timeout: 60000 })
21+
.should('not.be.empty')
22+
.invoke('text')
23+
.then((signature) => {
24+
25+
// Verify the signature
26+
cy.get('#verify-message').clear().type('Message to Sign\n' + signature);
27+
cy.get('#verify-pubkey').type(publicKey);
28+
cy.get('#form-verify button[type="submit"]').click();
29+
cy.get('#output-verify', { timeout: 60000 })
30+
.should('contain', 'Signature is valid');
31+
});
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)