chore: Refactor server tests to use jest
This commit is contained in:
committed by
mrugesh mohapatra
parent
4a9d22cee0
commit
438bd94895
@ -1,38 +0,0 @@
|
||||
import _ from 'lodash/fp';
|
||||
|
||||
// we don't store loop protect disable key
|
||||
export const removeNoprotect = _.replace(/noprotect/gi, '');
|
||||
|
||||
export const encodeScriptTags = _.flow(
|
||||
_.replace(/<script>/gi, 'fccss'),
|
||||
_.replace(/<\/script>/gi, 'fcces')
|
||||
);
|
||||
|
||||
export const decodeScriptTags = _.flow(
|
||||
_.replace(/fccss/gi, '<script>'),
|
||||
_.replace(/fcces/gi, '</script>')
|
||||
);
|
||||
|
||||
export const encodeFormAction = _.replace(
|
||||
// look for attributes in a form
|
||||
/<form[^>]*>/,
|
||||
// val is the string within the opening form tag
|
||||
// look for an `action` attribute, replace it with a fcc tag
|
||||
_.replace(/action(\s*?)=/, 'fccfaa$1=')
|
||||
);
|
||||
|
||||
export const decodeFormAction = _.replace(
|
||||
/<form[^>]*>/,
|
||||
_.replace(/fccfaa(\s*?)=/, 'action$1=')
|
||||
);
|
||||
|
||||
export const encodeFcc = _.flow(
|
||||
removeNoprotect,
|
||||
encodeFormAction,
|
||||
encodeScriptTags
|
||||
);
|
||||
|
||||
export const decodeFcc = _.flow(
|
||||
decodeFormAction,
|
||||
decodeScriptTags
|
||||
);
|
@ -1,70 +0,0 @@
|
||||
import test from 'tape';
|
||||
import {
|
||||
encodeScriptTags,
|
||||
decodeScriptTags,
|
||||
encodeFormAction,
|
||||
decodeFormAction,
|
||||
encodeFcc,
|
||||
decodeFcc
|
||||
} from './encode-decode.js';
|
||||
|
||||
const scriptDecoded = `
|
||||
<script>console.log('foo')</script>
|
||||
`;
|
||||
const scriptEncoded = `
|
||||
fccssconsole.log('foo')fcces
|
||||
`;
|
||||
test('encodeScriptTags', t => {
|
||||
t.plan(1);
|
||||
t.equal(
|
||||
encodeScriptTags(scriptDecoded),
|
||||
scriptEncoded
|
||||
);
|
||||
});
|
||||
|
||||
test('decodeScriptTags', t => {
|
||||
t.plan(1);
|
||||
t.equal(
|
||||
decodeScriptTags(scriptEncoded),
|
||||
scriptDecoded
|
||||
);
|
||||
});
|
||||
|
||||
const formDecoded = `
|
||||
<form action ='path'>foo</form>
|
||||
`;
|
||||
const formEncoded = `
|
||||
<form fccfaa ='path'>foo</form>
|
||||
`;
|
||||
|
||||
test('encodeFormAction', t => {
|
||||
t.plan(1);
|
||||
t.equal(
|
||||
encodeFormAction(formDecoded),
|
||||
formEncoded
|
||||
);
|
||||
});
|
||||
|
||||
test('decodeFormAction', t => {
|
||||
t.plan(1);
|
||||
t.equal(
|
||||
decodeFormAction(formEncoded),
|
||||
formDecoded
|
||||
);
|
||||
});
|
||||
|
||||
test('encodeFcc', t => {
|
||||
t.plan(1);
|
||||
t.equal(
|
||||
encodeFcc('//noprotect' + scriptDecoded + formDecoded),
|
||||
'//' + scriptEncoded + formEncoded
|
||||
);
|
||||
});
|
||||
|
||||
test('decodeFcc', t => {
|
||||
t.plan(1);
|
||||
t.equal(
|
||||
decodeFcc(scriptEncoded + formEncoded),
|
||||
scriptDecoded + formDecoded
|
||||
);
|
||||
});
|
Reference in New Issue
Block a user