Socket
Socket
Sign inDemoInstall

clarity

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.5 to 1.0.0

.travis.yml

350

index.js

@@ -1,106 +0,292 @@

var data = {},
reObfuscatedUser = /([\w\-]+)\:(\*+)/,
reObfuscatedVariable = /\*{2}([\w\-]+)(\|.*)?\*{2}/,
hasOwn = Object.prototype.hasOwnProperty;
/* jshint node: true */
'use strict';
function clarity() {
var reObfuscatedUser = /([\w\-]+)\:(\*+)/;
var reObfuscatedVariable = /\*{2}([\w\-\.]+)(\|.*)?\*{2}/;
var hasOwn = Object.prototype.hasOwnProperty;
/**
# clarity
Clarity is a small utility library that is used to provide "deobfuscation"
support for your secure data. The library has been created to deal with
the fact that configuration information is generally stored in plaintext
and saved to repositories such as source control, or centralized
configuration stores (at least that is the idea behind
[sharedconfig](https://github.com/DamonOehlman/sharedconfig).
When this happens, it's very easy to accidently leak passwords or other
information that should remain hidden.
Clarity makes it possible to store generalized information in these
centralized stores, while storing more sensitive information in alternative
stores and will reconcile the information at runtime when required.
## Replacing Simple Values
The most common use case when using clarity is to use it to replace
configuration values with configuration values that are stored in
environment variables. For instance, consider the following simple
example `config.json` file:
```json
{
"dbserver": "localhost",
"dbport": "7632",
"dbuser": "admin",
"dbpass": "teapot"
}
```
If we were then to import our configuration into our node program, we
would be able to access the configuration values:
```js
var config = require('./config.json');
```
Using this technique for configuration, however, means that we don't
have configurations for each of our environments (dev, test, staging,
production) and we have also exposed some sensitive data in our
configuration file. While we can use a package such as
[node-config](https://github.com/lorenwest/node-config) to assist with
managing configurations for different environments, we still have
potentially sensitive information stored in our configuration files.
This can be avoided by using clarity to put value placeholders in our
configuration instead:
```json
{
"dbserver": "**DB_SERVER**",
"dbport": "**DB_PORT**",
"dbuser": "**DB_USER**",
"dbpass": "**DB_PASS**"
}
```
Now if we were to load the configuration via clarity we could use
machine environment variables to replace the values:
```js
var clarity = require('clarity')(process.env);
var config = clarity.decode(require('./config.json'));
```
All values that have appropriate environment variables (e.g.
`process.env.DB_SERVER`) would be replaced with the relevant value
instead. The only downside of this technique is that in development you
need a whole swag of environment variables configured which can be quite
annoying.
To make life easier in development, you can use the default value
functionality of clarity. This is implemented by separating the
environment key with the default value using a pipe (|) character:
```json
{
"dbserver": "**DB_SERVER|localhost**",
"dbport": "**DB_PORT|7632**",
"dbuser": "**DB_USER|admin**",
"dbpass": "**DB_PASS|teapot**"
}
```
## Replacing values from nested data
It is possible to access nested data values using a period to traverse
the data structure. Such as:
```json
{
"dbserver": "**database.host**",
"dbport": "**database.port**",
"dbuser": "**database.user**",
"dbpass": "**database.password**"
}
```
## Reference
**/
/**
### Clarity constructor
Create a new instance of clarity.
```js
var clarity = require('clarity')(process.env);
```
Which is equivalent to:
```js
var Clarity = require('clarity');
var clarity = new Clarity(process.env);
```
**/
function Clarity(data) {
if (! (this instanceof Clarity)) {
return new Clarity(data);
}
// initialise empty data
this.data = {};
// use the provided data
this.use(data);
}
module.exports = Clarity;
/**
## clear
### Clarity#clear()
Clear the data currently stored within the clarity store
*/
clarity.clear = function() {
data = {};
return clarity;
Clear the data currently stored within the clarity store
**/
Clarity.prototype.clear = function() {
this.data = {};
return this;
};
clarity.decode = function(input) {
var matchUser, matchVariable, output, parts;
/**
### Clarity#decode(input)
// if the input is an object, then walk through the object and clone
if (typeof input == 'object' && (! (input instanceof String))) {
return clarity.deepDecode(input);
Decode the specified input value into it's actual value.
*/
Clarity.prototype.decode = function(input) {
var matchUser;
var matchVariable;
var output;
var parts;
var replacement;
function transverse(data, depth) {
var block;
if (depth.length === 1) {
return data[depth.shift()] || ''
}
// run some regex checks against the input string
matchUser = reObfuscatedUser.exec(input);
matchVariable = reObfuscatedVariable.exec(input);
output = input;
parts = [];
// if we are dealing with a variable, then decode appropriately
// for users, we will be looking for the key %username%_pass (yes, lowercase)
if (matchUser) {
// initialise the parts of the response
parts[0] = input.slice(0, matchUser.index);
parts[1] = matchUser[1] + ':' + (data[(matchUser[1] + '_pass').toLowerCase()] || matchUser[2]);
parts[2] = input.slice(matchUser.index + matchUser[0].length);
// create the output
output = parts.join('');
block = data[depth.shift()];
if (!block || typeof block !== 'object') {
return '';
}
else if (matchVariable) {
parts[0] = input.slice(0, matchVariable.index);
parts[1] = data[matchVariable[1]] || matchVariable[2].slice(1);
parts[2] = input.slice(matchVariable.index + matchVariable[0].length);
output = parts.join('');
}
return output;
};
return transverse(block, depth);
}
clarity.deepDecode = function(input) {
var clone = {};
// if the input is an object, then walk through the object and clone
if (typeof input == 'object' && (! (input instanceof String))) {
return this.deepDecode(input);
}
// run some regex checks against the input string
matchUser = reObfuscatedUser.exec(input);
matchVariable = reObfuscatedVariable.exec(input);
output = input;
parts = [];
// if we are dealing with a variable, then decode appropriately
// for users, we will be looking for the key %username%_pass (yes, lowercase)
if (matchUser) {
// initialise the parts of the response
parts[0] = input.slice(0, matchUser.index);
parts[1] = matchUser[1] + ':' + (this.data[(matchUser[1] + '_pass').toLowerCase()] || matchUser[2]);
parts[2] = input.slice(matchUser.index + matchUser[0].length);
// if we have a string, then short circuit
if (typeof input == 'string' || (input instanceof String)) {
return clarity.decode(input);
// create the output
output = parts.join('');
}
else if (matchVariable) {
parts[0] = input.slice(0, matchVariable.index);
if (matchVariable[1]) {
replacement = this.data[matchVariable[1]] ||
transverse(this.data, matchVariable[1].split('.'));
}
// likewise if we have a type other than an object
// then simple return the input
else if (typeof input != 'object') {
return input;
}
// iterate through the keys within the object
// and return the decoded value
Object.keys(input).forEach(function(key) {
if (hasOwn.call(input, key)) {
clone[key] = clarity.deepDecode(input[key]);
}
});
return clone;
// If there is no replacement data use the default
parts[1] = replacement || matchVariable[2] && matchVariable[2].slice(1);
parts[2] = input.slice(matchVariable.index + matchVariable[0].length);
output = parts.join('');
}
return output;
};
clarity.use = function() {
function extend() {
var dest = {},
sources = Array.prototype.slice.call(arguments),
source = sources.shift();
/**
### Clarity#deepDecode(input)
while (source) {
Object.keys(source).forEach(function(key) {
if (hasOwn.call(source, key)) {
dest[key] = source[key];
}
});
The `deepDecode` method is used to unpack an object and decode each
of the values within the object into it's actual value.
source = sources.shift();
**/
Clarity.prototype.deepDecode = function(input) {
var clone = {};
var clarity = this;
// if we have a string, then short circuit
if (typeof input == 'string' || (input instanceof String)) {
return this.decode(input);
}
// likewise if we have a type other than an object
// then simple return the input
else if (typeof input != 'object') {
return input;
}
// If input is an array. Then return an array with it's
// elements deep copied.
if (input instanceof Array) {
return input.map(clarity.deepDecode.bind(clarity));
}
// iterate through the keys within the object
// and return the decoded value
Object.keys(input).forEach(function(key) {
if (hasOwn.call(input, key)) {
clone[key] = clarity.deepDecode(input[key]);
}
});
return clone;
};
/**
### Clarity#use(data*)
Extend the data stored within clarity with additional data that will be
used at decode time.
**/
Clarity.prototype.use = function() {
function extend() {
var dest = {};
var sources = Array.prototype.slice.call(arguments);
var source = sources.shift();
while (source) {
Object.keys(source).forEach(function(key) {
if (hasOwn.call(source, key)) {
dest[key] = source[key];
}
});
return dest;
source = sources.shift();
}
// update the current data with the supplied sources
data = extend.apply(null, [data].concat(Array.prototype.slice.call(arguments)));
// return clarity
return clarity;
};
return dest;
}
module.exports = clarity;
// update the current data with the supplied sources
this.data = extend.apply(null, [this.data].concat([].slice.call(arguments)));
// return clarity
return this;
};
{
"name": "clarity",
"description": "Simple utility to convert obfuscated strings (primary use case is password urls) into the actual equivalent",
"author": "Damon Oehlman <damon.oehlman@sidelab.com>",
"tags": [
"author": "Damon Oehlman <damon.oehlman@gmail.com>",
"keywords": [
"password",

@@ -10,11 +10,6 @@ "obfuscate",

],
"version": "0.1.5",
"engines": {
"node": ">= 0.6.x < 0.9.0"
},
"dependencies": {
"debug": "*"
},
"version": "1.0.0",
"dependencies": {},
"devDependencies": {
"mocha": "1.4.x"
"tape": "~1.0.4"
},

@@ -29,6 +24,10 @@ "repository": {

"scripts": {
"test": "./node_modules/.bin/mocha --reporter spec"
"test": "node test/all.js",
"gendocs": "gendocs > README.md"
},
"contributors": [],
"optionalDependencies": {}
"main": "index.js",
"directories": {
"test": "test"
},
"license": "MIT"
}
# clarity
Clarity is a small utility library that is used to provide "deobfuscation" support for your secure data. The library has been created to deal with the fact that configuration information is generally stored in plaintext and saved to repositories such as source control, or centralized configuration stores (at least that is the idea behind [sharedconfig](https://github.com/DamonOehlman/sharedconfig). When this happens, it's very easy to accidently leak passwords or other information that should remain hidden.
Clarity is a small utility library that is used to provide "deobfuscation"
support for your secure data. The library has been created to deal with
the fact that configuration information is generally stored in plaintext
and saved to repositories such as source control, or centralized
configuration stores (at least that is the idea behind
[sharedconfig](https://github.com/DamonOehlman/sharedconfig).
Clarity makes it possible to store generalized information in these centralized stores, while storing more sensitive information in alternative stores and will reconcile the information at runtime when required.
When this happens, it's very easy to accidently leak passwords or other
information that should remain hidden.
Clarity makes it possible to store generalized information in these
centralized stores, while storing more sensitive information in alternative
stores and will reconcile the information at runtime when required.
[![NPM](https://nodei.co/npm/clarity.png)](https://nodei.co/npm/clarity/)
[![Build Status](https://travis-ci.org/DamonOehlman/clarity.png?branch=master)](https://travis-ci.org/DamonOehlman/clarity)
[![stable](http://hughsk.github.io/stability-badges/dist/stable.svg)](http://github.com/hughsk/stability-badges)
[![browser support](https://ci.testling.com/DamonOehlman/clarity.png)](https://ci.testling.com/DamonOehlman/clarity)
## Replacing Simple Values
The most common use case when using clarity is to use it to replace configuration values with configuration values that are stored in environment variables. For instance, consider the following simple example `config.json` file:
The most common use case when using clarity is to use it to replace
configuration values with configuration values that are stored in
environment variables. For instance, consider the following simple
example `config.json` file:
```
```json
{
"dbserver": "localhost",
"dbport": "7632",
"dbuser": "admin",
"dbpass": "teapot"
"dbserver": "localhost",
"dbport": "7632",
"dbuser": "admin",
"dbpass": "teapot"
}
```
If we were then to import our configuration into our node program, we would be able to access the configuration values:
If we were then to import our configuration into our node program, we
would be able to access the configuration values:

@@ -26,33 +49,117 @@ ```js

Using this technique for configuration, however, means that we don't have configurations for each of our environments (dev, test, staging, production) and we have also exposed some sensitive data in our configuration file. While we can use a package such as [node-config](https://github.com/lorenwest/node-config) to assist with managing configurations for different environments, we still have potentially sensitive information stored in our configuration files.
Using this technique for configuration, however, means that we don't
have configurations for each of our environments (dev, test, staging,
production) and we have also exposed some sensitive data in our
configuration file. While we can use a package such as
[node-config](https://github.com/lorenwest/node-config) to assist with
managing configurations for different environments, we still have
potentially sensitive information stored in our configuration files.
This can be avoided by using clarity to put value placeholders in our configuration instead:
This can be avoided by using clarity to put value placeholders in our
configuration instead:
```
```json
{
"dbserver": "**DB_SERVER**",
"dbport": "**DB_PORT**",
"dbuser": "**DB_USER**",
"dbpass": "**DB_PASS**"
"dbserver": "**DB_SERVER**",
"dbport": "**DB_PORT**",
"dbuser": "**DB_USER**",
"dbpass": "**DB_PASS**"
}
```
Now if we were to load the configuration via clarity we could use machine environment variables to replace the values:
Now if we were to load the configuration via clarity we could use
machine environment variables to replace the values:
```js
var clarity = require('clarity').use(process.env),
config = clarity.decode(require('./config.json'));
var clarity = require('clarity')(process.env);
var config = clarity.decode(require('./config.json'));
```
All values that have appropriate environment variables (e.g. `process.env.DB_SERVER`) would be replaced with the relevant value instead. The only downside of this technique is that in development you need a whole swag of environment variables configured which can be quite annoying.
All values that have appropriate environment variables (e.g.
`process.env.DB_SERVER`) would be replaced with the relevant value
instead. The only downside of this technique is that in development you
need a whole swag of environment variables configured which can be quite
annoying.
To make life easier in development, you can use the default value functionality of clarity. This is implemented by separating the environment key with the default value using a pipe (|) character:
To make life easier in development, you can use the default value
functionality of clarity. This is implemented by separating the
environment key with the default value using a pipe (|) character:
```json
{
"dbserver": "**DB_SERVER|localhost**",
"dbport": "**DB_PORT|7632**",
"dbuser": "**DB_USER|admin**",
"dbpass": "**DB_PASS|teapot**"
}
```
## Replacing values from nested data
It is possible to access nested data values using a period to traverse
the data structure. Such as:
```json
{
"dbserver": "**DB_SERVER|localhost**",
"dbport": "**DB_PORT|7632**",
"dbuser": "**DB_USER|admin**",
"dbpass": "**DB_PASS|teapot**"
"dbserver": "**database.host**",
"dbport": "**database.port**",
"dbuser": "**database.user**",
"dbpass": "**database.password**"
}
```
```
## Reference
### Clarity constructor
Create a new instance of clarity.
```js
var clarity = require('clarity')(process.env);
```
Which is equivalent to:
```js
var Clarity = require('clarity');
var clarity = new Clarity(process.env);
```
### Clarity#clear()
Clear the data currently stored within the clarity store
### Clarity#deepDecode(input)
The `deepDecode` method is used to unpack an object and decode each
of the values within the object into it's actual value.
### Clarity#use(data*)
Extend the data stored within clarity with additional data that will be
used at decode time.
## License(s)
### MIT
Copyright (c) 2013 Damon Oehlman <damon.oehlman@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@@ -1,30 +0,28 @@

var assert = require('assert'),
clarity = require('..'),
testData = {};
var test = require('tape');
var clarity = require('..');
var config;
var input = {
name: '**test|Roger Rabbit**',
address: {
street: '12 **this-is-a-test-key|** Street',
suburb: 'Brisbane',
postcode: 4054
}
};
describe('default value usage', function() {
before(function() {
clarity.clear();
clarity.use(testData);
});
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(), 'created ok');
});
it('should be able to replace a simple key', function() {
var input = {
name: '**test|Roger Rabbit**',
address: {
street: '12 **this-is-a-test-key|** Street',
suburb: 'Brisbane',
postcode: 4054
}
};
assert.deepEqual(clarity.decode(input), {
name: 'Roger Rabbit',
address: {
street: '12 Street',
suburb: 'Brisbane',
postcode: 4054
}
});
});
test('replace a simple key with a default value', function(t) {
t.plan(1);
t.deepEqual(config.decode(input), {
name: 'Roger Rabbit',
address: {
street: '12 Street',
suburb: 'Brisbane',
postcode: 4054
}
});
});

@@ -1,33 +0,33 @@

var assert = require('assert'),
clarity = require('..'),
testData = {
'test': 'test',
'this-is-a-test-key': 'test'
};
var test = require('tape');
var clarity = require('..');
var config;
var testData = {
'test': 'test',
'this-is-a-test-key': 'test'
};
describe('object value replacement - deep', function() {
before(function() {
clarity.clear();
clarity.use(testData);
});
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(testData), 'created ok');
});
it('should be able to replace a simple key', function() {
var input = {
name: '**test**',
address: {
street: '12 **this-is-a-test-key** Street',
suburb: 'Brisbane',
postcode: 4054
}
};
assert.deepEqual(clarity.decode(input), {
name: 'test',
address: {
street: '12 test Street',
suburb: 'Brisbane',
postcode: 4054
}
});
});
test('replace a simple key within an object', function(t) {
var input = {
name: '**test**',
address: {
street: '12 **this-is-a-test-key** Street',
suburb: 'Brisbane',
postcode: 4054
}
};
t.plan(1);
t.deepEqual(config.decode(input), {
name: 'test',
address: {
street: '12 test Street',
suburb: 'Brisbane',
postcode: 4054
}
});
});

@@ -1,36 +0,39 @@

var assert = require('assert'),
clarity = require('..'),
testData = {
'test': 'test',
'this-is-a-test-key': 'test',
'this_is_another_test_key': 'test'
};
var test = require('tape');
var clarity = require('..');
var config;
var testData = {
'test': 'test',
'this-is-a-test-key': 'test',
'this_is_another_test_key': 'test'
};
describe('object value replacement - shallow', function() {
before(function() {
clarity.clear();
clarity.use(testData);
});
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(testData), 'created ok');
});
it('should be able to replace a simple key', function() {
assert.deepEqual(clarity.decode({ name: '**test**' }), { name: 'test' });
});
test('replace a simple key', function(t) {
t.plan(1);
t.deepEqual(config.decode({ name: '**test**' }), { name: 'test' });
});
it('should be able to replace a simple key (with dashes)', function() {
assert.deepEqual(
clarity.decode({ name: '**this-is-a-test-key**' }),
{ name: 'test' }
);
});
test('replace a simple key (with dashes)', function(t) {
t.plan(1);
t.deepEqual(
config.decode({ name: '**this-is-a-test-key**' }),
{ name: 'test' }
);
});
it('should be able to replace a simple key (with underscores)', function() {
assert.deepEqual(
clarity.decode({ name: '**this_is_another_test_key**'}),
{ name: 'test' }
);
});
test('replace a simple key (with underscores)', function(t) {
t.plan(1);
t.deepEqual(
config.decode({ name: '**this_is_another_test_key**'}),
{ name: 'test' }
);
});
it('should be able to replace occurrences of keys within other strings', function() {
assert.deepEqual(clarity.decode({ name: 'T**test**' }), { name: 'Ttest' });
});
test('replace occurrences of keys within other strings', function(t) {
t.plan(1);
t.deepEqual(config.decode({ name: 'T**test**' }), { name: 'Ttest' });
});

@@ -1,35 +0,32 @@

var assert = require('assert'),
clarity = require('..');
var test = require('tape');
var clarity = require('..');
var config;
describe('object value replacement - shallow', function() {
before(function() {
clarity.clear();
clarity.use(process.env);
});
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(process.env), 'created ok');
});
it('should be able to replace an common environment variable (USER)', function() {
assert.notEqual(clarity.decode('**USER**'), '**USER**');
});
test('replace an common environment variable (USER)', function(t) {
t.plan(1);
t.notEqual(config.decode('**USER**'), '**USER**');
});
it('should be able to replace an environment var within an object', function() {
var data = clarity.decode({ username: '**USER** '});
test('replace an environment var within an object', function(t) {
t.plan(1);
t.notEqual(config.decode({ username: '**USER**' }).username, '**USER**');
});
assert.notEqual(data.username, '**USER**');
});
test('replace an environment var with underscores', function(t) {
t.plan(1);
t.notEqual(config.decode({ sshAgentPID: '**SSH_AGENT_PID**' }).sshAgentPID, '**SSH_AGENT_PID**');
});
it('should be able to replace an environment var with underscores', function() {
var data = clarity.decode({ sshAgentPID: '**SSH_AGENT_PID**' });
assert.notEqual(data.sshAgentPID, '**SSH_AGENT_PID**');
});
it('should be able to replace an environment var deep within an object', function() {
var data = clarity.decode({
config: {
username: '**USER**'
}
});
assert.notEqual(data.config.username, '**USER**');
});
test('object value replacement - shallow', function(t) {
t.plan(1);
t.notEqual(config.decode({
config: {
username: '**USER**'
}
}).config.username, '**USER**');
});

@@ -1,25 +0,27 @@

var assert = require('assert'),
clarity = require('..'),
testData = {
'test': 'test',
'this-is-a-test-key': 'test'
};
var test = require('tape');
var clarity = require('..');
var config;
var testData = {
'test': 'test',
'this-is-a-test-key': 'test'
};
describe('simple key replacement tests', function() {
before(function() {
clarity.clear();
clarity.use(testData);
});
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(testData), 'created ok');
});
it('should be able to replace a simple key', function() {
assert.equal(clarity.decode('**test**'), 'test');
});
it('should be able to replace a simple key (with dashes)', function() {
assert.equal(clarity.decode('**this-is-a-test-key**'), 'test');
});
it('should be able to replace occurrences of keys within other strings', function() {
assert.equal(clarity.decode('T**test**'), 'Ttest');
});
test('replace a simple key', function(t) {
t.plan(1);
t.equal(config.decode('**test**'), 'test');
});
test('replace a simple key (with dashes)', function(t) {
t.plan(1);
t.equal(config.decode('**this-is-a-test-key**'), 'test');
});
test('replace occurrences of keys within other strings', function(t) {
t.plan(1);
t.equal(config.decode('T**test**'), 'Ttest');
});

@@ -1,22 +0,26 @@

var assert = require('assert'),
clarity = require('..'),
obfuscatedUrl = 'http://test:****@damonoehlman.iriscouch.com/clarity-tests',
decodedUrl = 'http://test:test@damonoehlman.iriscouch.com/clarity-tests';
var test = require('tape');
var clarity = require('..');
var config;
var obfuscatedUrl = 'http://test:****@damonoehlman.iriscouch.com/clarity-tests';
var decodedUrl = 'http://test:test@damonoehlman.iriscouch.com/clarity-tests';
describe('username replacement tests', function() {
before(clarity.clear);
it('should return the same string when no secret stores have been created', function() {
assert.equal(clarity.decode(obfuscatedUrl), obfuscatedUrl);
});
it('should be able to prime clarity with username / password keys', function() {
clarity.use({
test_pass: 'test'
});
})
it('should be able to decode the user string once it has valid keys', function() {
assert.equal(clarity.decode(obfuscatedUrl), decodedUrl);
});
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(), 'created');
});
test('return the same string when no secret stores have been created', function(t) {
t.plan(1);
t.equal(config.decode(obfuscatedUrl), obfuscatedUrl);
});
test('tell the config to use some additional data', function(t) {
t.plan(1);
config.use({ test_pass: 'test' });
t.equal(config.data.test_pass, 'test');
});
test('can decode the user string', function(t) {
t.plan(1);
t.equal(config.decode(obfuscatedUrl), decodedUrl);
});

@@ -1,22 +0,26 @@

var assert = require('assert'),
clarity = require('..'),
obfuscatedUrl = 'http://test-user:****@damonoehlman.iriscouch.com/clarity-tests',
decodedUrl = 'http://test-user:test@damonoehlman.iriscouch.com/clarity-tests';
var test = require('tape');
var clarity = require('..');
var config;
var obfuscatedUrl = 'http://test-user:****@damonoehlman.iriscouch.com/clarity-tests';
var decodedUrl = 'http://test-user:test@damonoehlman.iriscouch.com/clarity-tests';
describe('username replacement tests', function() {
before(clarity.clear);
test('create clarity', function(t) {
t.plan(1);
t.ok(config = clarity(), 'created');
});
it('should return the same string when no secret stores have been created', function() {
assert.equal(clarity.decode(obfuscatedUrl), obfuscatedUrl);
});
test('return the same string when no secret stores have been created', function(t) {
t.plan(1);
t.equal(config.decode(obfuscatedUrl), obfuscatedUrl);
});
it('should be able to prime clarity with username / password keys', function() {
clarity.use({
'test-user_pass': 'test'
});
})
test('tell the config to use some additional data', function(t) {
t.plan(1);
config.use({ 'test-user_pass': 'test' });
t.equal(config.data['test-user_pass'], 'test');
});
it('should be able to decode the user string once it has valid keys', function() {
assert.equal(clarity.decode(obfuscatedUrl), decodedUrl);
});
test('can decode the user string', function(t) {
t.plan(1);
t.equal(config.decode(obfuscatedUrl), decodedUrl);
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc