@wazo/sdk 0.43.1 → 0.43.2
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.
- package/dist/wazo-sdk.js +2 -2
- package/esm/__tests__/api-client.test.js +20 -0
- package/esm/api/auth.js +11 -0
- package/esm/simple/Auth.js +20 -0
- package/esm/simple/__tests__/Auth.test.js +65 -0
- package/esm/simple/index.js +2 -1
- package/esm/types/api/auth.d.ts +1 -0
- package/esm/types/api/auth.d.ts.map +1 -1
- package/esm/types/simple/Auth.d.ts +6 -0
- package/esm/types/simple/Auth.d.ts.map +1 -1
- package/esm/types/simple/index.d.ts +2 -1
- package/esm/types/simple/index.d.ts.map +1 -1
- package/lib/__tests__/api-client.test.js +20 -0
- package/lib/api/auth.js +11 -0
- package/lib/simple/Auth.js +24 -1
- package/lib/simple/__tests__/Auth.test.js +65 -0
- package/lib/simple/index.js +1 -0
- package/lib/types/api/auth.d.ts +1 -0
- package/lib/types/api/auth.d.ts.map +1 -1
- package/lib/types/simple/Auth.d.ts +6 -0
- package/lib/types/simple/Auth.d.ts.map +1 -1
- package/lib/types/simple/index.d.ts +2 -1
- package/lib/types/simple/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/api-client.test.ts +22 -0
- package/src/api/auth.ts +14 -0
- package/src/simple/Auth.ts +22 -0
- package/src/simple/__tests__/Auth.test.ts +91 -0
- package/src/simple/index.ts +2 -1
|
@@ -120,4 +120,95 @@ describe('simple/Auth', () => {
|
|
|
120
120
|
expect(Auth.onSetUsingEdgeServer).toHaveBeenCalledWith(false);
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
+
|
|
124
|
+
describe('initiateIdpAuthentication', () => {
|
|
125
|
+
const validResponse = { location: 'idp.com/auth', saml_session_id: 'a1b2C3d4' };
|
|
126
|
+
|
|
127
|
+
it('should return a `location` and `saml_session_id` if the response is ok', async () => {
|
|
128
|
+
const initiateIdpAuthentication = jest.fn(() =>
|
|
129
|
+
Promise.resolve({
|
|
130
|
+
ok: true,
|
|
131
|
+
status: 303,
|
|
132
|
+
json: () => Promise.resolve(validResponse),
|
|
133
|
+
}));
|
|
134
|
+
|
|
135
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
136
|
+
auth: {
|
|
137
|
+
initiateIdpAuthentication,
|
|
138
|
+
},
|
|
139
|
+
}));
|
|
140
|
+
|
|
141
|
+
const response = await Auth.initiateIdpAuthentication('example.com', 'https://myapp.xyz');
|
|
142
|
+
expect(response).toBe(validResponse);
|
|
143
|
+
});
|
|
144
|
+
it('should return a `NoSamlRouteError` if the response is a 404', async () => {
|
|
145
|
+
const initiateIdpAuthentication = jest.fn(() =>
|
|
146
|
+
Promise.resolve({
|
|
147
|
+
ok: false,
|
|
148
|
+
status: 404,
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
152
|
+
auth: {
|
|
153
|
+
initiateIdpAuthentication,
|
|
154
|
+
},
|
|
155
|
+
}));
|
|
156
|
+
|
|
157
|
+
await expect(Auth.initiateIdpAuthentication('example.com', 'https://myapp.xyz')).rejects.toThrow(
|
|
158
|
+
'No route found for saml sso',
|
|
159
|
+
);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('should return an error `message` if the response is NOT ok', async () => {
|
|
163
|
+
const initiateIdpAuthentication = jest.fn(() =>
|
|
164
|
+
Promise.resolve({
|
|
165
|
+
ok: false,
|
|
166
|
+
json: () => Promise.resolve({ message: 'an error message', reason: 'an error reason' }),
|
|
167
|
+
}));
|
|
168
|
+
|
|
169
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
170
|
+
auth: {
|
|
171
|
+
initiateIdpAuthentication,
|
|
172
|
+
},
|
|
173
|
+
}));
|
|
174
|
+
|
|
175
|
+
await expect(Auth.initiateIdpAuthentication('example.com', 'https://myapp.xyz')).rejects.toThrow(
|
|
176
|
+
'an error message',
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('should return an error `reason` if there is no `message` and the response is NOT ok', async () => {
|
|
181
|
+
const initiateIdpAuthentication = jest.fn(() =>
|
|
182
|
+
Promise.resolve({
|
|
183
|
+
ok: false,
|
|
184
|
+
json: () => Promise.resolve({ reason: 'an error reason' }),
|
|
185
|
+
}));
|
|
186
|
+
|
|
187
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
188
|
+
auth: {
|
|
189
|
+
initiateIdpAuthentication,
|
|
190
|
+
},
|
|
191
|
+
}));
|
|
192
|
+
|
|
193
|
+
await expect(Auth.initiateIdpAuthentication('example.com', 'https://myapp.xyz')).rejects.toThrow(
|
|
194
|
+
'an error reason',
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should return an error with a null message if there is no `message` and `reason`', async () => {
|
|
199
|
+
const initiateIdpAuthentication = jest.fn(() =>
|
|
200
|
+
Promise.resolve({
|
|
201
|
+
ok: false,
|
|
202
|
+
json: () => Promise.resolve({}),
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
(getApiClient as any).mockImplementation(() => ({
|
|
206
|
+
auth: {
|
|
207
|
+
initiateIdpAuthentication,
|
|
208
|
+
},
|
|
209
|
+
}));
|
|
210
|
+
|
|
211
|
+
await expect(Auth.initiateIdpAuthentication('example.com', 'https://myapp.xyz')).rejects.toThrow('');
|
|
212
|
+
});
|
|
213
|
+
});
|
|
123
214
|
});
|
package/src/simple/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable import/no-named-as-default */
|
|
2
2
|
/* global window */
|
|
3
|
-
import Auth, { InvalidSubscription, InvalidAuthorization, NoTenantIdError, NoDomainNameError } from './Auth';
|
|
3
|
+
import Auth, { InvalidSubscription, InvalidAuthorization, NoTenantIdError, NoDomainNameError, NoSamlRouteError } from './Auth';
|
|
4
4
|
import Phone from './Phone';
|
|
5
5
|
import Websocket from './Websocket';
|
|
6
6
|
import Room from './room/Room';
|
|
@@ -138,6 +138,7 @@ const Wazo = {
|
|
|
138
138
|
SFUNotAvailableError,
|
|
139
139
|
NoTenantIdError,
|
|
140
140
|
NoDomainNameError,
|
|
141
|
+
NoSamlRouteError,
|
|
141
142
|
};
|
|
142
143
|
|
|
143
144
|
if (typeof window !== 'undefined') {
|