Skip to content
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

add variable checker to full url checker #1737

Merged
merged 5 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion packages/altair-app/src/app/modules/altair/utils/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setByDotNotation, truncateText } from '.';
import { getFullUrl, setByDotNotation, truncateText } from '.';

describe('utils', () => {

Expand Down Expand Up @@ -48,4 +48,22 @@ describe('utils', () => {
expect(result).toBe('Lorem Ipsum is simply dummy text.');
});
});

describe('.getFullUrl', () => {
it('should not change the value when including env variable', () => {
const envVariable = '{{endpointUrl}}';
const result = getFullUrl(envVariable);
expect(result).toBe(envVariable);
});
it('should not change the value for a valid absolute url', () => {
const url = 'https://test.com/graphql';
const result = getFullUrl(url);
expect(result).toBe(url);
});
it('should prepend text with origin location', () => {
const endpoint = 'graphql';
const result = getFullUrl(endpoint);
expect(result).toBe(location.origin + "/" + endpoint);
});
})
})
6 changes: 6 additions & 0 deletions packages/altair-app/src/app/modules/altair/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import isElectron from 'altair-graphql-core/build/utils/is_electron';
import { debug } from './logger';
import { IDictionary } from '../interfaces/shared';
import fileDialog from 'file-dialog';
import { VARIABLE_REGEX } from '../services/environment/environment.service';

/**
* Download the specified data with the provided options
Expand Down Expand Up @@ -165,6 +166,11 @@ export const getFullUrl = (url: string) => {
return url;
}

// regex to test if given string is an environment variable
if (VARIABLE_REGEX.test(url)) {
return url;
}

if (!validUrl.isUri(url)) {
if (url.trim() === '*') {
return location.href;
Expand Down