-
Notifications
You must be signed in to change notification settings - Fork 860
Expands the secure_rel utility to handle elastic domains #1565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { isDomainSecure } from './url'; | ||
|
|
||
| describe(`url`, () => { | ||
| describe(`#isDomainSecure`, () => { | ||
| it(`returns true for secure domains`, () => { | ||
| expect(isDomainSecure('https://elastic.co')).toEqual(true); | ||
| expect(isDomainSecure('https://elastic.co/')).toEqual(true); | ||
| expect(isDomainSecure('https://www.elastic.co')).toEqual(true); | ||
| expect(isDomainSecure('https://docs.elastic.co')).toEqual(true); | ||
| expect(isDomainSecure('https://stats.elastic.co')).toEqual(true); | ||
| expect(isDomainSecure('https://lots.of.kids.elastic.co')).toEqual(true); | ||
| expect( | ||
| isDomainSecure('https://elastic.co/cool/url/with?lots=of¶ms') | ||
| ).toEqual(true); | ||
| }); | ||
|
|
||
| it(`returns false for unsecure domains`, () => { | ||
| expect(isDomainSecure('https://wwwelastic.co')).toEqual(false); | ||
| expect(isDomainSecure('https://www.zelastic.co')).toEqual(false); | ||
| expect(isDomainSecure('https://*elastic.co')).toEqual(false); | ||
| expect(isDomainSecure('http://elastic.com')).toEqual(false); | ||
| expect(isDomainSecure('https://elastic.co.now')).toEqual(false); | ||
| expect(isDomainSecure('elastic.co')).toEqual(false); | ||
| expect(isDomainSecure('smb://www.elastic.co')).toEqual(false); | ||
| expect( | ||
| isDomainSecure( | ||
| 'https://wwwelastic.co/cool/url/with?lots=of¶ms/https://elastic.co' | ||
| ) | ||
| ).toEqual(false); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| const isElasticDomain = /(https?:\/\/(.+?\.)?elastic\.co(\/[A-Za-z0-9\-\._~:\/\?#\[\]@!$&'\(\)\*\+,;\=]*)?)/g; | ||
|
||
|
|
||
| // In order for the domain to be secure the regex | ||
| // has to match _and_ the lengths of the match must | ||
| // be _exact_ since URL's can have other URL's as | ||
| // path or query params! | ||
| export const isDomainSecure = (url: string = '') => { | ||
| const matches = url.match(isElasticDomain); | ||
|
|
||
| if (!matches) { | ||
| return false; | ||
| } | ||
| const [match] = matches; | ||
|
|
||
| return match.length === url.length; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interface is expanded here. Uses a single object argument versus trying to add another argument since that felt weird given the optionality of those args. I also tried to consolidate the algo a bit to make it readable, but let me know if that's not the case!