mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 07:45:00 -04:00
commit
73716a2c44
4 changed files with 320 additions and 0 deletions
|
@ -43,6 +43,7 @@ import "./tests/Compress.mjs";
|
|||
import "./tests/ConditionalJump.mjs";
|
||||
import "./tests/Crypt.mjs";
|
||||
import "./tests/CSV.mjs";
|
||||
import "./tests/Cut.mjs";
|
||||
import "./tests/DateTime.mjs";
|
||||
import "./tests/ExtractEmailAddresses.mjs";
|
||||
import "./tests/Fork.mjs";
|
||||
|
|
101
tests/operations/tests/Cut.mjs
Normal file
101
tests/operations/tests/Cut.mjs
Normal file
|
@ -0,0 +1,101 @@
|
|||
/**
|
||||
* Cut operation tests
|
||||
*
|
||||
* @author emilhf [emil@cyberops.no]
|
||||
*
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import TestRegister from "../../lib/TestRegister.mjs";
|
||||
|
||||
TestRegister.addTests([
|
||||
{
|
||||
name: "Extract single field",
|
||||
input: "test1,test2,test3",
|
||||
expectedOutput: "test2",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "1", "\\n", "\\n", ",", ","],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Extract range",
|
||||
input: "test1,test2,test3",
|
||||
expectedOutput: "test2,test3",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "1-2", "\\n", "\\n", ",", ","],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Extract reverse range",
|
||||
input: "test1,test2,test3",
|
||||
expectedOutput: "test2,test1",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "1-0", "\\n", "\\n", ",", ","],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Extract multiple ranges",
|
||||
input: "test1,test2,test3",
|
||||
expectedOutput: "test2,test3,test1",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "1-2,0", "\\n", "\\n", ",", ","],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Combine two existing fields",
|
||||
input: "john.doe,CONTOSO\nadams,CONTOSO",
|
||||
expectedOutput: "john.doe@CONTOSO\nadams@CONTOSO",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "0 \"@\" 1", "\\n", "\\n", ",", ","],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Fixed width to CSV",
|
||||
input: "abcdefghijklmnopqrstuvxyz",
|
||||
expectedOutput: "abc,xyz",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "0-2, 22-24", "\\n", "\\n", "", ","],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Extract and convert CSV to TSV",
|
||||
input: "ITEM,VALUE\nflamingo,439\nvodka,14",
|
||||
expectedOutput: "ITEM\tVALUE\nflamingo\t439\nvodka\t14",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "0-", "\\n", "\\n", ",", "\\t"],
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Extract with wrong delimiter",
|
||||
input: "test1,test2",
|
||||
expectedOutput: "test1,test2",
|
||||
recipeConfig: [
|
||||
{
|
||||
op: "Cut",
|
||||
args: ["User defined", "0-", "\\n", "\\n", "\\t", ";"],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
Loading…
Add table
Add a link
Reference in a new issue