-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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