-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 4.5] Fix IPV6 visualizations (#4920)
Fix IPV6 visualizations (#4909) * create compression function * Implement IPv6 compressor * Fix visualization in agent view * Create unit tests for ipv6-services * Update changelog * Add data type verification * Migrate to ts * Migrate to ts * Update to match the styleguide Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com> (cherry picked from commit a83bc15) Co-authored-by: Nico Guevara <42900763+Tostti@users.noreply.github.com>
- Loading branch information
1 parent
63637c4
commit 7989a7e
Showing
5 changed files
with
66 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { compressIPv6 } from "./ipv6-services"; | ||
|
||
describe('[settings] Input validation', () => { | ||
it.each` | ||
value | expectedValidation | ||
${'192.168.100.1'} | ${'192.168.100.1'} | ||
${'FE80:1234:2223:A000:2202:B3FF:FE1E:8329'} | ${'FE80:1234:2223:A000:2202:B3FF:FE1E:8329'} | ||
${'FE80:0034:0223:A000:0002:B3FF:0000:8329'} | ${'FE80:34:223:A000:2:B3FF:0:8329'} | ||
${'FE80:1234:2223:0000:0000:B3FF:FE1E:8329'} | ${'FE80:1234:2223::B3FF:FE1E:8329'} | ||
${'FE80:0000:0000:A000:0000:0000:0000:8329'} | ${'FE80:0:0:A000::8329'} | ||
${'FE80:0000:0000:0000:2202:00FF:0E1E:8329'} | ${'FE80::2202:FF:E1E:8329'} | ||
${'0000:0000:0000:0000:2202:00FF:0E1E:8329'} | ${'::2202:FF:E1E:8329'} | ||
${'2202:00FF:0E1E:8329:2202:0000:0000:0000'} | ${'2202:FF:E1E:8329:2202::'} | ||
${'0000:0000:0000:0000:0000:0000:0000:0000'} | ${'::'} | ||
${undefined} | ${undefined} | ||
${234} | ${234} | ||
`('$value | $expectedValidation', ({ value, expectedValidation }) => { | ||
expect( | ||
compressIPv6(value)).toBe(expectedValidation); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export function compressIPv6 (ip: string) { | ||
if (typeof (ip) !== 'string') { | ||
return ip; | ||
} | ||
if (ip?.split(':').length !== 8) { | ||
return ip; | ||
} | ||
|
||
let output = ip.split(':').map(terms => terms.replace(/\b0+/g, '') || '0').join(':'); | ||
const zeros = Array.from(output.matchAll(/\b:?(?:0+:?){2,}/g)); | ||
if (zeros.length > 0) { | ||
let max = ''; | ||
zeros.forEach(item => { | ||
if (item[0].replace(/:/g, '').length > max.replace(/:/g, '').length) { | ||
max = item[0]; | ||
} | ||
}); | ||
output = output.replace(max, '::'); | ||
} | ||
return output; | ||
} |