allow https

This commit is contained in:
arc-alex
2023-12-04 17:05:07 +01:00
parent 2a3c7f28ff
commit 7f095f0f06
5 changed files with 18 additions and 15 deletions
+1
View File
@@ -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?:\/\//;
@@ -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';
@@ -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({
@@ -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`)} />
@@ -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}`);
@@ -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);
});
});
+2 -1
View File
@@ -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;
}