Skip to content

Commit

Permalink
allow https
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-Arc committed Dec 4, 2023
1 parent 2a3c7f2 commit 7f095f0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions apps/client/src/common/utils/regex.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const isOnlyNumbers = /^\d+$/;
export const isIPAddress = /^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$/;
export const startsWithHttp = /^http:\/\//;
export const startsWithHttpOrS = /^https?:\/\//;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IoRemove } from '@react-icons/all-files/io5/IoRemove';
import { HttpSettings, TimerLifeCycle } from 'ontime-types';

import { useEmitLog } from '../../../../common/stores/logger';
import { startsWithHttp } from '../../../../common/utils/regex';
import { startsWithHttpOrS } from '../../../../common/utils/regex';

import collapseStyles from '../../../../common/components/collapse-bar/CollapseBar.module.scss';
import styles from '../../Modal.module.scss';
Expand Down Expand Up @@ -36,7 +36,7 @@ export default function SubscriptionRow(props: SubscriptionRowProps) {

const handleAddNew = () => {
if (hasTooManyOptions) {
emitError('Maximum amount of onLoad subscriptions reached (3)');
emitError(`Maximum amount of ${cycle} subscriptions reached (3)`);
return;
}
append({
Expand Down Expand Up @@ -71,7 +71,7 @@ export default function SubscriptionRow(props: SubscriptionRowProps) {
variant='ontime-filled-on-light'
autoComplete='off'
{...register(`subscriptions.${cycle}.${index}.message`, {
pattern: { value: startsWithHttp, message: 'Request address must start with http://' },
pattern: { value: startsWithHttpOrS, message: 'Request address must start with http://' },
})}
/>
<Switch variant='ontime-on-light' {...register(`subscriptions.${cycle}.${index}.enabled`)} />
Expand Down
14 changes: 7 additions & 7 deletions apps/server/src/services/integration-service/HttpIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
const parsedMessage = parseTemplateNested(message, state || {});
try {
const parsedUrl = new globalThis.URL(parsedMessage);
if (parsedUrl.protocol != 'http:') {
logger.error(LogOrigin.Tx, `HTTP Integration: Only HTTP allowed, got ${parsedUrl.protocol}`);
return {
success: false,
message: `Only HTTP allowed, got ${parsedUrl.protocol}`,
};
}
// if (parsedUrl.protocol != 'http:') {
// logger.error(LogOrigin.Tx, `HTTP Integration: Only HTTP allowed, got ${parsedUrl.protocol}`);
// return {
// success: false,
// message: `Only HTTP allowed, got ${parsedUrl.protocol}`,
// };
// }
this.emit(parsedUrl);
} catch (err) {
logger.error(LogOrigin.Tx, `HTTP Integration: ${err}`);
Expand Down
9 changes: 5 additions & 4 deletions apps/server/src/utils/__tests__/parserFunctions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,22 @@ describe('validateHttpSubscriptionCycle()', () => {
it('should return false when given an HttpSubscription with an invalid property value', () => {
const invalidBoolean = [{ message: 'http://', enabled: 'not a boolean' }];
const invalidHttp = [{ message: 'test', enabled: true }];
const noHttps = [{ message: 'https://test', enabled: true }];
const noFtp = [{ message: 'ftp://test', enabled: true }];
const noEmpty = [{ message: '', enabled: true }];

// @ts-expect-error -- since this comes from the client, we check things that typescript would have caught
expect(validateHttpSubscriptionCycle(invalidBoolean)).toBe(false);

expect(validateHttpSubscriptionCycle(invalidHttp)).toBe(false);
expect(validateHttpSubscriptionCycle(noHttps)).toBe(false);
expect(validateHttpSubscriptionCycle(noFtp)).toBe(false);
expect(validateHttpSubscriptionCycle(noEmpty)).toBe(false);
});
it('should return true when given an HttpSubscription matches definition', () => {
const validHttp = [{ message: 'http://', enabled: true }];
const validHttps = [{ message: 'https://', enabled: true }];

const result = validateHttpSubscriptionCycle(validHttp);
expect(result).toBe(true);
expect(validateHttpSubscriptionCycle(validHttp)).toBe(true);
expect(validateHttpSubscriptionCycle(validHttps)).toBe(true);
});
});

Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/utils/parserFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ export const parseOsc = (data: { osc?: Partial<OSCSettings> }): OSCSettings => {
*/
export const validateHttpSubscriptionCycle = (data: HttpSubscriptionOptions[]): boolean => {
for (const subscriptionOption of data) {
const isHttp = subscriptionOption.message?.startsWith('http://');
const isHttp =
subscriptionOption.message?.startsWith('http://') || subscriptionOption.message?.startsWith('https://');
if (typeof subscriptionOption.message !== 'string' || !isHttp || typeof subscriptionOption.enabled !== 'boolean') {
return false;
}
Expand Down

0 comments on commit 7f095f0

Please sign in to comment.