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.
This commit is contained in:
parent
4dcaa4df36
commit
6b067fe470
3 changed files with 9 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
|||
import $ from 'jquery';
|
||||
import { setUrlParam, removeUrlParam } from '~/lib/utils/common_utils';
|
||||
|
||||
/**
|
||||
* OAuth-based login buttons have a separate "remember me" checkbox.
|
||||
|
@ -24,9 +25,9 @@ export default class OAuthRememberMe {
|
|||
const href = $(element).attr('href');
|
||||
|
||||
if (rememberMe) {
|
||||
$(element).attr('href', `${href}?remember_me=1`);
|
||||
$(element).attr('href', setUrlParam(href, 'remember_me', 1));
|
||||
} else {
|
||||
$(element).attr('href', href.replace('?remember_me=1', ''));
|
||||
$(element).attr('href', removeUrlParam(href, 'remember_me'));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
|
||||
%a.oauth-login.twitter{ 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', () => {
|
|||
expect($('#oauth-container .oauth-login.github').attr('href')).toBe(
|
||||
'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', () => {
|
||||
|
@ -28,5 +32,6 @@ describe('OAuthRememberMe', () => {
|
|||
|
||||
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.facebook').attr('href')).toBe('http://example.com/?redirect_fragment=L1');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue