updates to operation and addition of more tests

This commit is contained in:
jb30795 2024-09-20 10:46:09 +01:00
parent a80b1568ac
commit 488c458720
2 changed files with 34 additions and 12 deletions

View file

@ -43,7 +43,7 @@ class IPv6TransitionAddresses extends Operation {
* @returns {string} * @returns {string}
*/ */
run(input, args) { run(input, args) {
const XOR = {"0": "2", "1": "3", "2": "0", "3": "1", "4": "6", "5": "7", "6": "4", "7": "5", "8": "A", "9": "B", "A": "8", "B": "9", "C": "E", "D": "F", "E": "C", "F": "D"}; const XOR = {"0": "2", "1": "3", "2": "0", "3": "1", "4": "6", "5": "7", "6": "4", "7": "5", "8": "a", "9": "b", "a": "8", "b": "9", "c": "e", "d": "f", "e": "c", "f": "d"};
/** /**
* Function to convert to hex * Function to convert to hex
@ -126,12 +126,13 @@ class IPv6TransitionAddresses extends Operation {
*/ */
function macTransition(input) { function macTransition(input) {
let output = ""; let output = "";
console.log(input);
const MACPARTS = input.split(":"); const MACPARTS = input.split(":");
if (!args[1]) { if (!args[1]) {
output += "EUI-64 Interface ID: "; output += "EUI-64 Interface ID: ";
} }
const MAC = MACPARTS[0] + MACPARTS[1] + ":" + MACPARTS[2] + "ff:fe" + MACPARTS[3] + ":" + MACPARTS[4] + MACPARTS[5]; const MAC = MACPARTS[0] + MACPARTS[1] + ":" + MACPARTS[2] + "ff:fe" + MACPARTS[3] + ":" + MACPARTS[4] + MACPARTS[5];
output += MAC.slice(0, 1) + XOR[MAC.slice(1, 2).toUpperCase()].toLowerCase() + MAC.slice(2); output += MAC.slice(0, 1) + XOR[MAC.slice(1, 2)] + MAC.slice(2);
return output; return output;
} }
@ -183,17 +184,18 @@ class IPv6TransitionAddresses extends Operation {
let inputs = input.split("\n"); let inputs = input.split("\n");
// Remove blank rows // Remove blank rows
inputs = inputs.filter(Boolean); inputs = inputs.filter(Boolean);
for (let input = 0; input < inputs.length; input++) {
for (let i = 0; i < inputs.length; i++) {
// if ignore ranges is checked and input is a range, skip // if ignore ranges is checked and input is a range, skip
if ((args[0] && !inputs[input].includes("/")) || (!args[0])) { if ((args[0] && !inputs[i].includes("/")) || (!args[0])) {
if (/^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/.test(inputs[input])) { if (/^[0-9]{1,3}(?:\.[0-9]{1,3}){3}$/.test(inputs[i])) {
output += ipTransition(inputs[input], false); output += ipTransition(inputs[i], false);
} else if (/\/24$/.test(inputs[input])) { } else if (/\/24$/.test(inputs[i])) {
output += ipTransition(inputs[input], true); output += ipTransition(inputs[i], true);
} else if (/^([0-9A-F]{2}:){5}[0-9A-F]{2}$/.test(inputs[input].toUpperCase())) { } else if (/^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$/.test(inputs[i])) {
output += macTransition(input.toLowerCase()); output += macTransition(inputs[i]);
} else if (/^((?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(inputs[input])) { } else if (/^((?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(?::[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(?:ffff(?::0{1,4}){0,1}:){0,1}(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])|(?:[0-9a-fA-F]{1,4}:){1,4}:(?:(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(?:25[0-5]|(?:2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test(inputs[i])) {
output += unTransition(inputs[input]); output += unTransition(inputs[i]);
} else { } else {
output = "Enter compressed or expanded IPv6 address, IPv4 address or MAC Address."; output = "Enter compressed or expanded IPv6 address, IPv4 address or MAC Address.";
} }

View file

@ -19,6 +19,26 @@ TestRegister.addTests([
args: [true, false], args: [true, false],
}, },
], ],
}, {
name: "IPv6 Transition: IPv4 /24 Range to IPv6",
input: "198.51.100.0/24",
expectedOutput: "6to4: 2002:c633:6400::/40\nIPv4 Mapped: ::ffff:c633:6400/120\nIPv4 Translated: ::ffff:0:c633:6400/120\nNat 64: 64:ff9b::c633:6400/120",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [false, false],
},
],
}, {
name: "IPv6 Transition: IPv4 to IPv6 Remove headers",
input: "198.51.100.7",
expectedOutput: "2002:c633:6407::/48\n::ffff:c633:6407\n::ffff:0:c633:6407\n64:ff9b::c633:6407",
recipeConfig: [
{
op: "IPv6 Transition Addresses",
args: [true, true],
},
],
}, { }, {
name: "IPv6 Transition: IPv6 to IPv4", name: "IPv6 Transition: IPv6 to IPv4",
input: "64:ff9b::c633:6407", input: "64:ff9b::c633:6407",