-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Add IPv6 bracket-wrapping to network serializer (#6007)
This addresses the issue raised by @pznamensky in #5966.
- Loading branch information
Showing
5 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,20 @@ | ||
import ApplicationSerializer from './application'; | ||
import isIp from 'is-ip'; | ||
|
||
export default ApplicationSerializer.extend({ | ||
attrs: { | ||
cidr: 'CIDR', | ||
ip: 'IP', | ||
mbits: 'MBits', | ||
}, | ||
|
||
normalize(typeHash, hash) { | ||
const ip = hash.IP; | ||
|
||
if (isIp.v6(ip)) { | ||
hash.IP = `[${ip}]`; | ||
} | ||
|
||
return this._super(...arguments); | ||
}, | ||
}); |
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,31 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
import NetworkModel from 'nomad-ui/models/network'; | ||
|
||
module('Unit | Serializer | Network', function(hooks) { | ||
setupTest(hooks); | ||
hooks.beforeEach(function() { | ||
this.store = this.owner.lookup('service:store'); | ||
this.subject = () => this.store.serializerFor('network'); | ||
}); | ||
|
||
test('v4 IPs are passed through', async function(assert) { | ||
const ip = '10.0.13.12'; | ||
const original = { | ||
IP: ip, | ||
}; | ||
|
||
const { data } = this.subject().normalize(NetworkModel, original); | ||
assert.equal(data.attributes.ip, ip); | ||
}); | ||
|
||
test('v6 IPs are wrapped in square brackets', async function(assert) { | ||
const ip = '2001:0dac:aba3:0000:0000:8a2e:0370:7334'; | ||
const original = { | ||
IP: ip, | ||
}; | ||
|
||
const { data } = this.subject().normalize(NetworkModel, original); | ||
assert.equal(data.attributes.ip, `[${ip}]`); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -6569,6 +6569,11 @@ invert-kv@^1.0.0: | |
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" | ||
integrity sha1-EEqOSqym09jNFXqO+L+rLXo//bY= | ||
|
||
ip-regex@^4.0.0: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-4.1.0.tgz#5ad62f685a14edb421abebc2fff8db94df67b455" | ||
integrity sha512-pKnZpbgCTfH/1NLIlOduP/V+WRXzC2MOz3Qo8xmxk8C5GudJLgK5QyLVXOSWy3ParAH7Eemurl3xjv/WXYFvMA== | ||
|
||
[email protected]: | ||
version "1.8.0" | ||
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.8.0.tgz#eaa33d6ddd7ace8f7f6fe0c9ca0440e706738b1e" | ||
|
@@ -6719,6 +6724,13 @@ is-glob@^4.0.0: | |
dependencies: | ||
is-extglob "^2.1.1" | ||
|
||
is-ip@^3.1.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-3.1.0.tgz#2ae5ddfafaf05cb8008a62093cf29734f657c5d8" | ||
integrity sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q== | ||
dependencies: | ||
ip-regex "^4.0.0" | ||
|
||
is-number@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" | ||
|