4ad691fa2f
The Consul API can pass through `Value: null` which does not get cast to a string by ember-data. This snowballs into problems with `atob` which then tried to decode `null`. There are 2 problems here. 1. `Value` should never be `null` - I've added a removeNull function to shallowly loop though props and remove properties that are `null`, for the moment this is only on single KV JSON responses - therefore `Value` will never be `null` which is the root of the problem 2. `atob` doesn't quite follow the `window.atob` API in that the `window.atob` API casts everything down to a string first, therefore it will try to decode `null` > `'null'` > `crazy unicode thing`. - I've commented in a fix for this, but whilst this shouldn't be causing anymore problems in our UI (now that `Value` is never `null`), I'll uncomment it in another future release. Tests are already written for it which more closely follow `window.atob` but skipped for now (next commit)
68 lines
1.3 KiB
JavaScript
68 lines
1.3 KiB
JavaScript
import { module } from 'ember-qunit';
|
||
import test from 'ember-sinon-qunit/test-support/test';
|
||
import { skip } from 'qunit';
|
||
import atob from 'consul-ui/utils/atob';
|
||
module('Unit | Utils | atob', {});
|
||
|
||
skip('it decodes non-strings properly', function(assert) {
|
||
[
|
||
{
|
||
test: ' ',
|
||
expected: '',
|
||
},
|
||
{
|
||
test: new String(),
|
||
expected: '',
|
||
},
|
||
{
|
||
test: new String('MTIzNA=='),
|
||
expected: '1234',
|
||
},
|
||
{
|
||
test: [],
|
||
expected: '',
|
||
},
|
||
{
|
||
test: [' '],
|
||
expected: '',
|
||
},
|
||
{
|
||
test: new Array(),
|
||
expected: '',
|
||
},
|
||
{
|
||
test: ['MTIzNA=='],
|
||
expected: '1234',
|
||
},
|
||
{
|
||
test: null,
|
||
expected: '<27><>e',
|
||
},
|
||
].forEach(function(item) {
|
||
const actual = atob(item.test);
|
||
assert.equal(actual, item.expected);
|
||
});
|
||
});
|
||
test('it decodes strings properly', function(assert) {
|
||
[
|
||
{
|
||
test: '',
|
||
expected: '',
|
||
},
|
||
{
|
||
test: 'MTIzNA==',
|
||
expected: '1234',
|
||
},
|
||
].forEach(function(item) {
|
||
const actual = atob(item.test);
|
||
assert.equal(actual, item.expected);
|
||
});
|
||
});
|
||
test('throws when passed the wrong value', function(assert) {
|
||
[{}, ['MTIz', 'NA=='], new Number(), 'hi'].forEach(function(item) {
|
||
assert.throws(function() {
|
||
atob(item);
|
||
});
|
||
});
|
||
});
|