Skip to content

Commit 0ec8e3d

Browse files
committed
Add tests for dangerouslyAllowInsecureHttpRequests
1 parent a8095ee commit 0ec8e3d

File tree

1 file changed

+106
-2
lines changed

1 file changed

+106
-2
lines changed

index.spec.js

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ jest.mock('react-native', () => ({
77
refresh: jest.fn(),
88
},
99
},
10+
Platform: {
11+
OS: 'ios',
12+
},
1013
}));
1114

1215
describe('AppAuth', () => {
@@ -65,7 +68,7 @@ describe('AppAuth', () => {
6568
}).toThrow('Scope error: please add at least one scope');
6669
});
6770

68-
it('calls the native wrapper with the correct args', () => {
71+
it('calls the native wrapper with the correct args on iOS', () => {
6972
authorize(config);
7073
expect(mockAuthorize).toHaveBeenCalledWith(
7174
config.issuer,
@@ -75,6 +78,52 @@ describe('AppAuth', () => {
7578
config.additionalParameters
7679
);
7780
});
81+
82+
describe('Android-specific dangerouslyAllowInsecureHttpRequests parameter', () => {
83+
beforeEach(() => {
84+
require('react-native').Platform.OS = 'android';
85+
});
86+
87+
afterEach(() => {
88+
require('react-native').Platform.OS = 'ios';
89+
});
90+
91+
it('calls the native wrapper with default value `false`', () => {
92+
authorize(config);
93+
expect(mockAuthorize).toHaveBeenCalledWith(
94+
config.issuer,
95+
config.redirectUrl,
96+
config.clientId,
97+
config.scopes,
98+
config.additionalParameters,
99+
false
100+
);
101+
});
102+
103+
it('calls the native wrapper with passed value `false`', () => {
104+
authorize({ ...config, dangerouslyAllowInsecureHttpRequests: false });
105+
expect(mockAuthorize).toHaveBeenCalledWith(
106+
config.issuer,
107+
config.redirectUrl,
108+
config.clientId,
109+
config.scopes,
110+
config.additionalParameters,
111+
false
112+
);
113+
});
114+
115+
it('calls the native wrapper with passed value `true`', () => {
116+
authorize({ ...config, dangerouslyAllowInsecureHttpRequests: true });
117+
expect(mockAuthorize).toHaveBeenCalledWith(
118+
config.issuer,
119+
config.redirectUrl,
120+
config.clientId,
121+
config.scopes,
122+
config.additionalParameters,
123+
true
124+
);
125+
});
126+
});
78127
});
79128

80129
describe('refresh', () => {
@@ -119,7 +168,7 @@ describe('AppAuth', () => {
119168
}).toThrow('Scope error: please add at least one scope');
120169
});
121170

122-
it('calls the native wrapper with the correct args', () => {
171+
it('calls the native wrapper with the correct args on iOS', () => {
123172
refresh({ ...config }, { refreshToken: 'such-token' });
124173
expect(mockRefresh).toHaveBeenCalledWith(
125174
config.issuer,
@@ -130,5 +179,60 @@ describe('AppAuth', () => {
130179
config.additionalParameters
131180
);
132181
});
182+
183+
describe('Android-specific dangerouslyAllowInsecureHttpRequests parameter', () => {
184+
beforeEach(() => {
185+
require('react-native').Platform.OS = 'android';
186+
});
187+
188+
afterEach(() => {
189+
require('react-native').Platform.OS = 'ios';
190+
});
191+
192+
it('calls the native wrapper with default value `false`', () => {
193+
refresh(config, { refreshToken: 'such-token' });
194+
expect(mockRefresh).toHaveBeenCalledWith(
195+
config.issuer,
196+
config.redirectUrl,
197+
config.clientId,
198+
'such-token',
199+
config.scopes,
200+
config.additionalParameters,
201+
false
202+
);
203+
});
204+
205+
it('calls the native wrapper with passed value `false`', () => {
206+
refresh(
207+
{ ...config, dangerouslyAllowInsecureHttpRequests: false },
208+
{ refreshToken: 'such-token' }
209+
);
210+
expect(mockRefresh).toHaveBeenCalledWith(
211+
config.issuer,
212+
config.redirectUrl,
213+
config.clientId,
214+
'such-token',
215+
config.scopes,
216+
config.additionalParameters,
217+
false
218+
);
219+
});
220+
221+
it('calls the native wrapper with passed value `true`', () => {
222+
refresh(
223+
{ ...config, dangerouslyAllowInsecureHttpRequests: true },
224+
{ refreshToken: 'such-token' }
225+
);
226+
expect(mockRefresh).toHaveBeenCalledWith(
227+
config.issuer,
228+
config.redirectUrl,
229+
config.clientId,
230+
'such-token',
231+
config.scopes,
232+
config.additionalParameters,
233+
true
234+
);
235+
});
236+
});
133237
});
134238
});

0 commit comments

Comments
 (0)