Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.

Commit c6dbefd

Browse files
committed
Merge pull request #3 from conjurinc/role-graph
Role graph
2 parents 70d955d + 05e05ef commit c6dbefd

20 files changed

Lines changed: 844 additions & 546 deletions

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
xunit.xml
2+
report/
13
*.log
24
conjur-api.js
3-
integration-result.xml
45
integration/testdata
56
integration/policy.json
6-
test-result.xml
77
test.log
88
node_modules
99
*.iml
10-
.idea
10+
.idea

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM dockerfile/nodejs
2+
3+
ADD . /app
4+
5+
WORKDIR /app
6+
7+
RUN npm update

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@
33
# Testing
44

55
* Install global dependencies
6-
7-
$ sudo npm install -g mocha coffee-script
6+
```
7+
$ sudo npm install -g mocha coffee-script gulp
8+
```
89

910
* Load the test data set
10-
11+
```
1112
$ cd integration
1213
$ conjur policy load -c policy.json policy.rb
14+
```
15+
16+
* Configure gulp reporting (optional)
17+
```
18+
# To write reports to a file in xunit format
19+
$ export TEST_REPORTER=xunit-file
20+
$ export XUNIT_FILE=reports/report.xml
21+
```
1322

14-
* Run the tests
23+
* Run jslint and tests
24+
```
25+
$ gulp
26+
```
1527

16-
$ test.sh

gulpfile.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2013 Conjur Inc
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
* this software and associated documentation files (the "Software"), to deal in
6+
* the Software without restriction, including without limitation the rights to
7+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8+
* the Software, and to permit persons to whom the Software is furnished to do so,
9+
* subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
22+
"use strict";
23+
24+
var gulp = require('gulp'),
25+
jslint = require('gulp-jslint'),
26+
mocha = require('gulp-mocha'),
27+
silenceLogger = require('./testconfig');
28+
29+
require('coffee-script/register');
30+
31+
var sources = ['lib/**/*.js'];
32+
var tests = ['test/**/*_test.coffee'];
33+
34+
35+
function chooseMochaReporter(){
36+
// if TEST_REPORTER is set, use that
37+
if(process.env.TEST_REPORTER){
38+
return process.env.TEST_REPORTER;
39+
}
40+
41+
if(process.stdout.isTTY){
42+
// use the always popular nyancat reporter if we're
43+
// in someones terminal
44+
return 'nyan';
45+
}
46+
// spec is a useful format, and looks good whether or not you're
47+
// in a terminal.
48+
return 'spec';
49+
}
50+
51+
52+
53+
var mochaOpts = {
54+
reporter: chooseMochaReporter()
55+
};
56+
57+
var jslintOpts = {
58+
// assume node.js
59+
node: true,
60+
// don't worry about sloppy whitespace
61+
white: true,
62+
// this one makes regexps of any kind impossible to use,
63+
// for example it calls "." insecure, as well as "^", even
64+
// when using it in a character class like "[^foo]".
65+
regexp: true,
66+
// This one makes maintaining backwards compatibility more or less impossible.
67+
// See the xyzUrl functions in lib/config.js
68+
unparam: true,
69+
// don't print successes
70+
errorsOnly: true
71+
};
72+
73+
74+
gulp.task('lint', function(){
75+
return gulp.src(sources)
76+
.pipe(jslint(jslintOpts));
77+
});
78+
79+
gulp.task('test', function(){
80+
silenceLogger();
81+
return gulp.src(tests, {read: false})
82+
.pipe(mocha(mochaOpts));
83+
});
84+
85+
gulp.task('default', ['lint', 'test']);
86+
87+
gulp.task('watch', function(){
88+
gulp.watch(['lib/**/*.js', 'test/**/*.coffee', 'gulpfile.js'], ['default']);
89+
});

jenkins.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash -e
2+
3+
job=$JOB_NAME
4+
if [ -z $job ]; then
5+
job=sandbox
6+
fi
7+
8+
docker build -t api-node:$job .
9+
10+
rm -rf report
11+
mkdir report
12+
13+
docker run --rm -e TEST_REPORTER=xunit-file -e XUNIT_FILE=report/xunit.xml -v $PWD/report:/app/report api-node:$job node node_modules/gulp/bin/gulp.js
14+
15+
echo "Test results are available in report/xunit.xml"

lib/conjur/authn.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,36 @@
1818
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1919
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2020
*/
21+
"use strict";
2122

22-
var g = require('../global')
23+
var g = require('../global');
2324

2425
module.exports = {
25-
connect: function(url) {
26-
return {
27-
casLogin: function(ticket, callback) {
28-
var path = g.format(url + '/users/login?ticket=%s', ticket);
29-
g.getURL(path, callback);
30-
},
31-
authenticate: function(username, apiKey, callback) {
32-
var path = g.format(url + '/users/%s/authenticate', g.escape(username));
33-
g.info(g.format("POST %s", path));
34-
g.rest.post(path, { data: apiKey }).on('complete', function(token, response) {
35-
if ( token instanceof Error)
36-
return callback(token);
37-
else if ( response.statusCode !== 200 )
38-
return callback(g.format("POST %s failed : %s", path, response.statusCode));
39-
40-
callback(null, token);
41-
})
42-
}
26+
connect: function (url) {
27+
return {
28+
casLogin: function (ticket, callback) {
29+
var path = g.format(url + '/users/login?ticket=%s', ticket);
30+
g.getURL(path, callback);
31+
},
32+
authenticate: function (username, apiKey, callback) {
33+
var path = g.format(url + '/users/%s/authenticate', g.escape(username));
34+
g.info(g.format("POST %s", path));
35+
g.rest.post(path, {data: apiKey}).on('complete', function (token, response) {
36+
if (token instanceof Error){
37+
return callback(token);
38+
}
39+
if (response.statusCode !== 200) {
40+
return callback(g.format("POST %s failed : %s", path, response.statusCode));
41+
}
42+
callback(null, token);
43+
});
44+
}
45+
};
46+
},
47+
username: function (token) {
48+
return g.username(token);
49+
},
50+
tokenHeader: function (token) {
51+
return g.format('Token token="%s"', new Buffer(JSON.stringify(token)).toString('base64'));
4352
}
44-
},
45-
username: function(token) {
46-
return g.username(token);
47-
},
48-
tokenHeader: function(token) {
49-
return g.format('Token token="%s"', new Buffer(JSON.stringify(token)).toString('base64'))
50-
}
51-
}
53+
};

0 commit comments

Comments
 (0)