@webex/internal-plugin-calendar 3.0.0-beta.4 → 3.0.0-beta.400

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,145 @@
1
+ import sinon from "sinon";
2
+ import { expect } from "@webex/test-helper-chai";
3
+ import DecryptHelper from "@webex/internal-plugin-calendar/src/calendar.decrypt.helper";
4
+
5
+ describe("internal-plugin-calendar", () => {
6
+ describe("DecryptHelper", () => {
7
+ let ctx;
8
+ let encryptedSchedulerData;
9
+ let encryptedFreeBusyData;
10
+
11
+ beforeEach(() => {
12
+ ctx = {
13
+ webex: {
14
+ internal: {
15
+ encryption: {
16
+ decryptText: sinon.stub()
17
+ }
18
+ }
19
+ }
20
+ };
21
+
22
+ encryptedSchedulerData = {
23
+ encryptionKeyUrl: "http://example.com/encryption-key",
24
+ encryptedSubject: "some encrypted subject",
25
+ encryptedLocation: "some encrypted location",
26
+ encryptedNotes: "some encrypted notes",
27
+ encryptedParticipants: [
28
+ {
29
+ encryptedEmailAddress: "some encrypted email address",
30
+ encryptedName: "some encrypted name"
31
+ },
32
+ {
33
+ encryptedEmailAddress: "another encrypted email address",
34
+ encryptedName: "another encrypted name"
35
+ }
36
+ ],
37
+ encryptedScheduleFor: {
38
+ "user1@example.com": {
39
+ encryptedEmail: "some encrypted email address",
40
+ encryptedDisplayName: "some encrypted display name"
41
+ },
42
+ "user2@example.com": {
43
+ encryptedEmail: "another encrypted email address",
44
+ encryptedDisplayName: "another encrypted display name"
45
+ }
46
+ },
47
+ meetingJoinInfo: {
48
+ meetingJoinURI: "some encrypted meeting join URI",
49
+ meetingJoinURL: "some encrypted meeting join URL"
50
+ },
51
+ encryptedOrganizer: {
52
+ encryptedEmailAddress: "some encrypted email address",
53
+ encryptedName: "some encrypted name"
54
+ },
55
+ webexURI: "some encrypted webex URI",
56
+ webexURL: "some encrypted webex URL",
57
+ spaceMeetURL: "some encrypted space meet URL",
58
+ spaceURI: "some encrypted space URI",
59
+ spaceURL: "some encrypted space URL"
60
+ };
61
+
62
+ encryptedFreeBusyData = {
63
+ calendarFreeBusyScheduleResponse: {
64
+ encryptionKeyUrl: "https://encryption.key/url",
65
+ calendarFreeBusyItems: [
66
+ {
67
+ email: "encrypted-email"
68
+ }
69
+ ]
70
+ }
71
+ };
72
+ });
73
+
74
+ afterEach(() => {
75
+ sinon.restore();
76
+ });
77
+
78
+ it("#decryptSchedulerDataResponse - should resolve with undefined if data is undefined", async () => {
79
+ const decryptedData = await DecryptHelper.decryptSchedulerDataResponse(ctx, undefined);
80
+ expect(decryptedData).to.be.undefined;
81
+ });
82
+
83
+ it("#decryptSchedulerDataResponse - should resolve with undefined if data.encryptionKeyUrl is undefined", async () => {
84
+ encryptedSchedulerData.encryptionKeyUrl = undefined;
85
+ const decryptedData = await DecryptHelper.decryptSchedulerDataResponse(ctx, encryptedSchedulerData);
86
+ expect(decryptedData).to.be.undefined;
87
+ });
88
+
89
+ describe("#decryptSchedulerDataResponse - should replace encrypted data with decrypted data in response", () => {
90
+ it("should decrypt scheduler data response correctly", async () => {
91
+ // Stub the decryption method to return the plaintext value.
92
+ const expectedCiphertext = "some decrypted text for testing";
93
+
94
+ ctx.webex.internal.encryption.decryptText.callsFake((key, ciphertext) => Promise.resolve(expectedCiphertext));
95
+
96
+ // Decrypt the data.
97
+ await DecryptHelper.decryptSchedulerDataResponse(ctx, encryptedSchedulerData);
98
+
99
+ // Check that all encrypted properties were decrypted correctly.
100
+ expect(encryptedSchedulerData.encryptedSubject).to.equal(expectedCiphertext);
101
+ expect(encryptedSchedulerData.encryptedLocation).to.equal(expectedCiphertext);
102
+ expect(encryptedSchedulerData.encryptedNotes).to.equal(expectedCiphertext);
103
+ expect(encryptedSchedulerData.encryptedParticipants[0].encryptedEmailAddress).to.equal(expectedCiphertext);
104
+ expect(encryptedSchedulerData.encryptedParticipants[0].encryptedName).to.equal(expectedCiphertext);
105
+ expect(encryptedSchedulerData.encryptedScheduleFor["user1@example.com"].encryptedEmail).to.equal(expectedCiphertext);
106
+ expect(encryptedSchedulerData.encryptedScheduleFor["user1@example.com"].encryptedDisplayName).to.equal(expectedCiphertext);
107
+ expect(encryptedSchedulerData.meetingJoinInfo.meetingJoinURI).to.equal(expectedCiphertext);
108
+ expect(encryptedSchedulerData.meetingJoinInfo.meetingJoinURL).to.equal(expectedCiphertext);
109
+
110
+ expect(encryptedSchedulerData.encryptedOrganizer.encryptedEmailAddress).to.equal(expectedCiphertext);
111
+ expect(encryptedSchedulerData.encryptedOrganizer.encryptedName).to.equal(expectedCiphertext);
112
+ expect(encryptedSchedulerData.webexURI).to.equal(expectedCiphertext);
113
+ expect(encryptedSchedulerData.webexURL).to.equal(expectedCiphertext);
114
+ expect(encryptedSchedulerData.spaceMeetURL).to.equal(expectedCiphertext);
115
+ expect(encryptedSchedulerData.spaceURI).to.equal(expectedCiphertext);
116
+ expect(encryptedSchedulerData.spaceURL).to.equal(expectedCiphertext);
117
+ });
118
+ });
119
+
120
+ it("#decryptFreeBusyResponse - should resolve with undefined if data is undefined", async () => {
121
+ const decryptedData = await DecryptHelper.decryptFreeBusyResponse(ctx, undefined);
122
+ expect(decryptedData).to.be.undefined;
123
+ });
124
+
125
+ it("#decryptFreeBusyResponse - should resolve with undefined if data.calendarFreeBusyScheduleResponse is undefined", async () => {
126
+ const decryptedData = await DecryptHelper.decryptFreeBusyResponse(ctx, {});
127
+ expect(decryptedData).to.be.undefined;
128
+ });
129
+
130
+ it("#decryptFreeBusyResponse - should resolve with undefined if data.calendarFreeBusyScheduleResponse.encryptionKeyUrl is undefined", async () => {
131
+ encryptedFreeBusyData.calendarFreeBusyScheduleResponse.encryptionKeyUrl = undefined;
132
+ const decryptedData = await DecryptHelper.decryptFreeBusyResponse(ctx, encryptedFreeBusyData);
133
+ expect(decryptedData).to.be.undefined;
134
+ });
135
+
136
+ it("#decryptFreeBusyResponse - should replace encrypted email with decrypted email in calendarFreeBusyItems", async () => {
137
+ const decryptTextStub = ctx.webex.internal.encryption.decryptText;
138
+ decryptTextStub.resolves("decrypted-email");
139
+
140
+ await DecryptHelper.decryptFreeBusyResponse(ctx, encryptedFreeBusyData);
141
+
142
+ expect(encryptedFreeBusyData.calendarFreeBusyScheduleResponse.calendarFreeBusyItems[0].email).to.equal("decrypted-email");
143
+ });
144
+ });
145
+ });
@@ -0,0 +1,52 @@
1
+ import sinon from 'sinon';
2
+ import {expect} from '@webex/test-helper-chai';
3
+ import EncryptHelper from '@webex/internal-plugin-calendar/src/calendar.encrypt.helper';
4
+ describe('internal-plugin-calendar', () => {
5
+ describe('encryptHelper', () => {
6
+ let ctx;
7
+ beforeEach(() => {
8
+ ctx = {
9
+ encryptionKeyUrl: 'http://example.com/encryption-key',
10
+ webex: {
11
+ internal: {
12
+ encryption: {
13
+ encryptText: sinon.stub(),
14
+ },
15
+ },
16
+ },
17
+ };
18
+ });
19
+
20
+ afterEach(() => {
21
+ sinon.restore();
22
+ });
23
+
24
+ it('#encryptFreebusyRequestData with emails should ', async () => {
25
+ const freeBusyRequest = {
26
+ start: '20230712T10:20:00Z',
27
+ end: '20230712T20:20:00Z',
28
+ emails: ['test@webex.com'],
29
+ };
30
+ const expectedCiphertext = 'some encrpty data';
31
+ ctx.webex.internal.encryption.encryptText.callsFake((key, ciphertext) =>
32
+ Promise.resolve(expectedCiphertext)
33
+ );
34
+ await EncryptHelper.encryptFreeBusyRequest(ctx, freeBusyRequest);
35
+ expect(freeBusyRequest.emails[0]).to.be.equal(expectedCiphertext);
36
+ });
37
+
38
+ it('#encryptFreebusyRequestData not include emails, but include ids- should b', async () => {
39
+ const freeBusyRequest = {
40
+ start: '20230712T10:20:00Z',
41
+ end: '20230712T20:20:00Z',
42
+ userIds: ['91aee1231'],
43
+ };
44
+ const expectedCiphertext = '91aee1231';
45
+ ctx.webex.internal.encryption.encryptText.callsFake((key, ciphertext) =>
46
+ Promise.resolve(expectedCiphertext)
47
+ );
48
+ await EncryptHelper.encryptFreeBusyRequest(ctx, freeBusyRequest);
49
+ expect(freeBusyRequest.userIds[0]).to.equal(expectedCiphertext);
50
+ });
51
+ });
52
+ });