Commit 6b067fe4 authored by Scott Escue's avatar Scott Escue Committed by Mike Greiling

Updating OAuthRememberMe to use new common utility functions when manipulating...

Updating OAuthRememberMe to use new common utility functions when manipulating query parameters on OAuth buttons. This ensures the 'remember_me' parameter is safely added and removed when other query parameters are present.
parent 4dcaa4df
import $ from 'jquery'; import $ from 'jquery';
import { setUrlParam, removeUrlParam } from '~/lib/utils/common_utils';
/** /**
* OAuth-based login buttons have a separate "remember me" checkbox. * OAuth-based login buttons have a separate "remember me" checkbox.
...@@ -24,9 +25,9 @@ export default class OAuthRememberMe { ...@@ -24,9 +25,9 @@ export default class OAuthRememberMe {
const href = $(element).attr('href'); const href = $(element).attr('href');
if (rememberMe) { if (rememberMe) {
$(element).attr('href', `${href}?remember_me=1`); $(element).attr('href', setUrlParam(href, 'remember_me', 1));
} else { } else {
$(element).attr('href', href.replace('?remember_me=1', '')); $(element).attr('href', removeUrlParam(href, 'remember_me'));
} }
}); });
} }
......
...@@ -3,3 +3,4 @@ ...@@ -3,3 +3,4 @@
%a.oauth-login.twitter{ href: "http://example.com/" } %a.oauth-login.twitter{ href: "http://example.com/" }
%a.oauth-login.github{ href: "http://example.com/" } %a.oauth-login.github{ href: "http://example.com/" }
%a.oauth-login.facebook{ href: "http://example.com/?redirect_fragment=L1" }
...@@ -20,6 +20,10 @@ describe('OAuthRememberMe', () => { ...@@ -20,6 +20,10 @@ describe('OAuthRememberMe', () => {
expect($('#oauth-container .oauth-login.github').attr('href')).toBe( expect($('#oauth-container .oauth-login.github').attr('href')).toBe(
'http://example.com/?remember_me=1', 'http://example.com/?remember_me=1',
); );
expect($('#oauth-container .oauth-login.facebook').attr('href')).toBe(
'http://example.com/?redirect_fragment=L1&remember_me=1'
);
}); });
it('removes the "remember_me" query parameter from all OAuth login buttons', () => { it('removes the "remember_me" query parameter from all OAuth login buttons', () => {
...@@ -28,5 +32,6 @@ describe('OAuthRememberMe', () => { ...@@ -28,5 +32,6 @@ 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');
}); });
}); });
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