Commit 2cbc475e authored by Scott Escue's avatar Scott Escue Committed by Mike Greiling

Fixing static analysis issues

parent a3541a8d
...@@ -13,7 +13,7 @@ export default function preserveUrlFragment(fragment) { ...@@ -13,7 +13,7 @@ export default function preserveUrlFragment(fragment) {
// Append the fragment to all sign-in/sign-up form actions so it is preserved when the user is // Append the fragment to all sign-in/sign-up form actions so it is preserved when the user is
// eventually redirected back to the originally requested URL. // eventually redirected back to the originally requested URL.
const forms = document.querySelectorAll('#signin-container form'); const forms = document.querySelectorAll('#signin-container form');
Array.prototype.forEach.call(forms, (form) => { Array.prototype.forEach.call(forms, form => {
const actionWithFragment = setUrlFragment(form.getAttribute('action'), `#${normalFragment}`); const actionWithFragment = setUrlFragment(form.getAttribute('action'), `#${normalFragment}`);
form.setAttribute('action', actionWithFragment); form.setAttribute('action', actionWithFragment);
}); });
...@@ -21,8 +21,11 @@ export default function preserveUrlFragment(fragment) { ...@@ -21,8 +21,11 @@ export default function preserveUrlFragment(fragment) {
// Append a redirect_fragment query param to all oauth provider links. The redirect_fragment // Append a redirect_fragment query param to all oauth provider links. The redirect_fragment
// query param will be available in the omniauth callback upon successful authentication // query param will be available in the omniauth callback upon successful authentication
const anchors = document.querySelectorAll('#signin-container a.oauth-login'); const anchors = document.querySelectorAll('#signin-container a.oauth-login');
Array.prototype.forEach.call(anchors, (anchor) => { Array.prototype.forEach.call(anchors, anchor => {
const newHref = mergeUrlParams({ redirect_fragment: normalFragment }, anchor.getAttribute('href')); const newHref = mergeUrlParams(
{ redirect_fragment: normalFragment },
anchor.getAttribute('href'),
);
anchor.setAttribute('href', newHref); anchor.setAttribute('href', newHref);
}); });
} }
......
...@@ -32,8 +32,13 @@ describe('URL utility', () => { ...@@ -32,8 +32,13 @@ describe('URL utility', () => {
expect(urlUtils.mergeUrlParams({ w: 1 }, '#frag')).toBe('?w=1#frag'); expect(urlUtils.mergeUrlParams({ w: 1 }, '#frag')).toBe('?w=1#frag');
expect(urlUtils.mergeUrlParams({ w: 1 }, '/path#frag')).toBe('/path?w=1#frag'); expect(urlUtils.mergeUrlParams({ w: 1 }, '/path#frag')).toBe('/path?w=1#frag');
expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path')).toBe('https://host/path?w=1'); expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path')).toBe('https://host/path?w=1');
expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path#frag')).toBe('https://host/path?w=1#frag'); expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://host/path#frag')).toBe(
expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://h/p?k1=v1#frag')).toBe('https://h/p?k1=v1&w=1#frag'); 'https://host/path?w=1#frag',
);
expect(urlUtils.mergeUrlParams({ w: 1 }, 'https://h/p?k1=v1#frag')).toBe(
'https://h/p?k1=v1&w=1#frag',
);
}); });
it('updates w', () => { it('updates w', () => {
...@@ -59,21 +64,25 @@ describe('URL utility', () => { ...@@ -59,21 +64,25 @@ describe('URL utility', () => {
it('should remove param when url has no other params', () => { it('should remove param when url has no other params', () => {
const url = urlUtils.removeParams(['size'], '/feature/home?size=5'); const url = urlUtils.removeParams(['size'], '/feature/home?size=5');
expect(url).toBe('/feature/home'); expect(url).toBe('/feature/home');
}); });
it('should remove param when url has other params', () => { it('should remove param when url has other params', () => {
const url = urlUtils.removeParams(['size'], '/feature/home?q=1&size=5&f=html'); const url = urlUtils.removeParams(['size'], '/feature/home?q=1&size=5&f=html');
expect(url).toBe('/feature/home?q=1&f=html'); expect(url).toBe('/feature/home?q=1&f=html');
}); });
it('should remove param and preserve fragment', () => { it('should remove param and preserve fragment', () => {
const url = urlUtils.removeParams(['size'], '/feature/home?size=5#H2'); const url = urlUtils.removeParams(['size'], '/feature/home?size=5#H2');
expect(url).toBe('/feature/home#H2'); expect(url).toBe('/feature/home#H2');
}); });
it('should remove multiple params', () => { it('should remove multiple params', () => {
const url = urlUtils.removeParams(['z', 'a'], '/home?z=11111&l=en_US&a=true#H2'); const url = urlUtils.removeParams(['z', 'a'], '/home?z=11111&l=en_US&a=true#H2');
expect(url).toBe('/home?l=en_US#H2'); expect(url).toBe('/home?l=en_US#H2');
}); });
}); });
...@@ -87,6 +96,7 @@ describe('URL utility', () => { ...@@ -87,6 +96,7 @@ describe('URL utility', () => {
}); });
const url = urlUtils.removeParams(['locale']); const url = urlUtils.removeParams(['locale']);
expect(url).toBe('https://mysite.com/?zip=11111&ads=false#privacy'); expect(url).toBe('https://mysite.com/?zip=11111&ads=false#privacy');
}); });
}); });
...@@ -95,16 +105,19 @@ describe('URL utility', () => { ...@@ -95,16 +105,19 @@ describe('URL utility', () => {
describe('setUrlFragment', () => { describe('setUrlFragment', () => {
it('should set fragment when url has no fragment', () => { it('should set fragment when url has no fragment', () => {
const url = urlUtils.setUrlFragment('/home/feature', 'usage'); const url = urlUtils.setUrlFragment('/home/feature', 'usage');
expect(url).toBe('/home/feature#usage'); expect(url).toBe('/home/feature#usage');
}); });
it('should set fragment when url has existing fragment', () => { it('should set fragment when url has existing fragment', () => {
const url = urlUtils.setUrlFragment('/home/feature#overview', 'usage'); const url = urlUtils.setUrlFragment('/home/feature#overview', 'usage');
expect(url).toBe('/home/feature#usage'); expect(url).toBe('/home/feature#usage');
}); });
it('should set fragment when given fragment includes #', () => { it('should set fragment when given fragment includes #', () => {
const url = urlUtils.setUrlFragment('/home/feature#overview', '#install'); const url = urlUtils.setUrlFragment('/home/feature#overview', '#install');
expect(url).toBe('/home/feature#install'); expect(url).toBe('/home/feature#install');
}); });
}); });
......
...@@ -22,7 +22,7 @@ describe('OAuthRememberMe', () => { ...@@ -22,7 +22,7 @@ describe('OAuthRememberMe', () => {
); );
expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe( expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe(
'http://example.com/?redirect_fragment=L1&remember_me=1' 'http://example.com/?redirect_fragment=L1&remember_me=1',
); );
}); });
...@@ -32,6 +32,8 @@ describe('OAuthRememberMe', () => { ...@@ -32,6 +32,8 @@ describe('OAuthRememberMe', () => {
expect($('#oauth-container .oauth-login.twitter').attr('href')).toBe('http://example.com/'); expect($('#oauth-container .oauth-login.twitter').attr('href')).toBe('http://example.com/');
expect($('#oauth-container .oauth-login.github').attr('href')).toBe('http://example.com/'); expect($('#oauth-container .oauth-login.github').attr('href')).toBe('http://example.com/');
expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe('http://example.com/?redirect_fragment=L1'); expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe(
'http://example.com/?redirect_fragment=L1',
);
}); });
}); });
...@@ -19,8 +19,16 @@ describe('preserve_url_fragment', () => { ...@@ -19,8 +19,16 @@ describe('preserve_url_fragment', () => {
it('adds the "redirect_fragment" query parameter to all OAuth and SAML login buttons', () => { it('adds the "redirect_fragment" query parameter to all OAuth and SAML login buttons', () => {
preserveUrlFragment('#L65'); preserveUrlFragment('#L65');
expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe('/users/auth/auth0?redirect_fragment=L65'); expect($('.omniauth-container #oauth-login-auth0').attr('href')).toBe(
expect($('.omniauth-container #oauth-login-facebook').attr('href')).toBe('/users/auth/facebook?remember_me=1&redirect_fragment=L65'); '/users/auth/auth0?redirect_fragment=L65',
expect($('.omniauth-container #oauth-login-saml').attr('href')).toBe('/users/auth/saml?redirect_fragment=L65'); );
expect($('.omniauth-container #oauth-login-facebook').attr('href')).toBe(
'/users/auth/facebook?remember_me=1&redirect_fragment=L65',
);
expect($('.omniauth-container #oauth-login-saml').attr('href')).toBe(
'/users/auth/saml?redirect_fragment=L65',
);
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment