Skip to content

Commit

Permalink
UI: Add IPv6 bracket-wrapping to network serializer (#6007)
Browse files Browse the repository at this point in the history
This addresses the issue raised by @pznamensky in #5966.
  • Loading branch information
backspace committed Jul 30, 2019
1 parent f09d2ef commit 2152d57
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.9.5 (Unreleased)

BUG FIXES:

* ui: Fixed links containing IPv6 addresses to include required square brackets [[GH-6007](https://github.com/hashicorp/nomad/pull/6007)]

## 0.9.4 (July 30, 2019)

IMPROVEMENTS:
Expand Down
11 changes: 11 additions & 0 deletions ui/app/serializers/network.js
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);
},
});
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"flat": "^4.0.0",
"fuse.js": "^3.4.4",
"husky": "^1.3.1",
"is-ip": "^3.1.0",
"ivy-codemirror": "^2.1.0",
"lint-staged": "^8.1.5",
"loader.js": "^4.7.0",
Expand Down
31 changes: 31 additions & 0 deletions ui/tests/unit/serializers/network-test.js
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}]`);
});
});
12 changes: 12 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==

ipaddr.js@1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.8.0.tgz#eaa33d6ddd7ace8f7f6fe0c9ca0440e706738b1e"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 2152d57

Please sign in to comment.