-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Introduce encryption service * Add page for encrypting with public key * Handle basic auth for remote specifications * Bye bye proxy - use remotes endpoint now * Encapsulate encoding/decoding of RemoteConfig --------- Co-authored-by: Simon B. Støvring <[email protected]>
- Loading branch information
1 parent
f368a66
commit ec4af52
Showing
18 changed files
with
657 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import RsaEncryptionService from '../../src/features/encrypt/EncryptionService' | ||
|
||
const publicKey = `-----BEGIN PUBLIC KEY----- | ||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAu1k4JT719AUz/wuXb2rt | ||
8933okfM2Iynmc6akSsZWEsW19byzO0UHp8b79xvsmNQKM1wBEBnXb5t+uLjJJZe | ||
rqCiTB7fBL64tExSKIDIRAlMnQtMfHs/rMgR+o/N2Yo2KimQw9G84goCEbBF2kbw | ||
5/MQfe43HeEoVWbNfgmRyP8VudO1UtVr07dGoUEWvFjudtd/h5H9THVdEpp2vH2Z | ||
pSGypn8hRAbOzhIM4ExLOH4ZHb8gPQGiHRGUYXk3Cy95RSf/SpEnRi0p4/63Nx5M | ||
JNXGM2Jk0RgGcYZcwJvLanT5Xdb9LM/IsDxLKXN+utDUgkzddvJbBC12aLaKaJA5 | ||
LwIDAQAB | ||
-----END PUBLIC KEY-----` | ||
|
||
const privateKey = `-----BEGIN PRIVATE KEY----- | ||
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7WTglPvX0BTP/ | ||
C5dvau3z3feiR8zY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DYLwKBgBeViB39GJ6vC16azzZ6XhmX95gl5HDUrMFBVKzqyhiupf1w64HF | ||
G+FZhP97BZO/Bt91nomg1FgUiMqVJkAF6cjtQ7YqVCHBtO0bLlA8iWNsQx31Spsj | ||
jIL6+NuIZL0i8tjoH2N8euVVH5mVNmiLnHGeicflZM4HHrm3BWHrlTQBAoGBALeW | ||
W98CQFe8Pw542ixDiESOR8fz6UwrXWAb/pwTxL20oKV8GUxJNFhtKJK3CEMZ2JB7 | ||
uWoEqYairvUTWOxSVeBQPPwSAWcNeE6f+0mKMGa1EQNIRDDLq3fOcNYevkOPKB7g | ||
kZQtQzclCAvGYQ8aJL6MmvY3DWOVx2YuD4+COE6BAoGAEGdChfJW5QGXaXEO/PnA | ||
PbQCCzcqbs+0O6LVR1w68H0WQww94tZjfWPqn9kvwjzLd22ZMmdiBJ3bEbDeCjmG | ||
Ybt48kS7y9n22CDgL7JkatszYpybvBSrDQL7ms7x2kKPkTMb7C5zpIIzdtvwH+Jf | ||
6K3kQbqfFCM7VmyR7AmoyOk= | ||
-----END PRIVATE KEY-----` | ||
|
||
const encryptionService = new RsaEncryptionService({ publicKey, privateKey }) | ||
|
||
describe('RsaEncryptionService', () => { | ||
it('should encrypt and decrypt data correctly', () => { | ||
const data = 'Hello, World!' | ||
const encryptedData = encryptionService.encrypt(data) | ||
const decryptedData = encryptionService.decrypt(encryptedData) | ||
|
||
expect(decryptedData).toBe(data) | ||
}) | ||
|
||
it('should throw an error when decrypting with incorrect data', () => { | ||
const incorrectData = 'invalidEncryptedData' | ||
|
||
expect(() => { | ||
encryptionService.decrypt(incorrectData) | ||
}).toThrow() | ||
}) | ||
|
||
it('should throw an error when encrypting with an invalid public key', () => { | ||
const invalidPublicKey = 'invalidPublicKey' | ||
const invalidEncryptionService = new RsaEncryptionService({ publicKey: invalidPublicKey, privateKey }) | ||
|
||
expect(() => { | ||
invalidEncryptionService.encrypt('test') | ||
}).toThrow() | ||
}) | ||
|
||
it('should throw an error when decrypting with an invalid private key', () => { | ||
const data = 'Hello, World!' | ||
const encryptedData = encryptionService.encrypt(data) | ||
const invalidPrivateKey = 'invalidPrivateKey' | ||
const invalidEncryptionService = new RsaEncryptionService({ publicKey, privateKey: invalidPrivateKey }) | ||
|
||
expect(() => { | ||
invalidEncryptionService.decrypt(encryptedData) | ||
}).toThrow() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.