Skip to content

Commit

Permalink
need to fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanovSPvirtru committed Sep 7, 2023
1 parent 5c63e38 commit 1e1beb6
Showing 1 changed file with 62 additions and 62 deletions.
124 changes: 62 additions & 62 deletions lib/tests/mocha/encrypt-decrypt.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import getMocks from '../mocks/index.js';
import { TDF } from '../../tdf3/src/index.js';
// import * as cryptoService from '../../tdf3/src/crypto/index.js';
// import { createSandbox } from 'sinon';
// import { assert } from 'chai';
// import { Binary } from '../../tdf3/src/binary.js';
import { Client, TDF } from '../../tdf3/src/index.js';
import * as cryptoService from '../../tdf3/src/crypto/index.js';
import { createSandbox } from 'sinon';
import { assert } from 'chai';
import { Binary } from '../../tdf3/src/binary.js';
import { HttpRequest } from '../../src/auth/auth.js';
const Mocks = getMocks();

Expand All @@ -18,61 +18,61 @@ describe('encrypt decrypt test', async function () {
const kasUrl = `http://localhost:4000/`;
const kasPublicKey = await TDF.extractPemFromKeyString(Mocks.kasPublicKey);

// it('encrypt-decrypt stream source happy path', async function () {
// const sandbox = createSandbox();
// try {
// const tdf1 = TDF.create({ cryptoService });
// sandbox.replace(
// TDF,
// 'create',
// sandbox.fake(() => tdf1)
// );
// sandbox.spy(tdf1, '_generateManifest');
// sandbox.stub(tdf1, 'unwrapKey').callsFake(async () => {
// // @ts-ignore
// const keyInfo = tdf1._generateManifest.lastCall.args[0];
// return {
// reconstructedKeyBinary: keyInfo.unwrappedKeyBinary as Binary,
// metadata: undefined,
// };
// });
// const client = new Client.Client({
// kasEndpoint: kasUrl,
// kasPublicKey,
// keypair: { publicKey: Mocks.entityPublicKey, privateKey: Mocks.entityPrivateKey },
// clientId: 'id',
// authProvider,
// });
//
// const eo = await Mocks.getEntityObject();
// const scope = Mocks.getScope();
//
// const encryptedStream = await client.encrypt({
// eo,
// metadata: Mocks.getMetadataObject(),
// offline: true,
// scope,
// source: new ReadableStream({
// start(controller) {
// controller.enqueue(new TextEncoder().encode(expectedVal));
// controller.close();
// },
// }),
// });
//
// const decryptStream = await client.decrypt({
// eo,
// source: {
// type: 'stream',
// location: encryptedStream.stream,
// },
// });
//
// const { value: decryptedText } = await decryptStream.stream.getReader().read();
//
// assert.equal(new TextDecoder().decode(decryptedText), expectedVal);
// } finally {
// sandbox.restore();
// }
// });
it('encrypt-decrypt stream source happy path', async function () {
const sandbox = createSandbox();
try {
const tdf1 = TDF.create({ cryptoService });
sandbox.replace(
TDF,
'create',
sandbox.fake(() => tdf1)
);
sandbox.spy(tdf1, '_generateManifest');
sandbox.stub(tdf1, 'unwrapKey').callsFake(async () => {
// @ts-ignore
const keyInfo = tdf1._generateManifest.lastCall.args[0];
return {
reconstructedKeyBinary: keyInfo.unwrappedKeyBinary as Binary,
metadata: undefined,
};
});
const client = new Client.Client({
kasEndpoint: kasUrl,
kasPublicKey,
keypair: { publicKey: Mocks.entityPublicKey, privateKey: Mocks.entityPrivateKey },
clientId: 'id',
authProvider,
});

const eo = await Mocks.getEntityObject();
const scope = Mocks.getScope();

const encryptedStream = await client.encrypt({
eo,
metadata: Mocks.getMetadataObject(),
offline: true,
scope,
source: new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode(expectedVal));
controller.close();
},
}),
});

const decryptStream = await client.decrypt({
eo,
source: {
type: 'stream',
location: encryptedStream.stream,
},
});

const { value: decryptedText } = await decryptStream.stream.getReader().read();

assert.equal(new TextDecoder().decode(decryptedText), expectedVal);
} finally {
sandbox.restore();
}
});
});

0 comments on commit 1e1beb6

Please sign in to comment.