Skip to content

Commit 08927d9

Browse files
committed
add customHeaders in accessControl
1 parent 65d25a3 commit 08927d9

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/accessControl.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-underscore-dangle */
12
const DispatchRequest = require('./dispatchRequest');
23
const ErrorMessage = require('./errorMessage');
34
const CONST = require('./const');
@@ -8,8 +9,10 @@ const typedef = require('./typedef');
89
* @license Apache Version 2
910
* @module AccessControl
1011
* @constructor AccessControl
11-
* @description The AccessControl object has various methods to control the access for users.
12-
* for the credential you can use the JWT token or the API token
12+
* @description The AccessControl is a driver to work with
13+
* TerminusDB and TerminusX access control api
14+
* for the credential you can use the JWT token, the API token or
15+
* the basic authentication with username and password
1316
* @example
1417
* //connect with the API token
1518
* //(to request a token create an account in https://terminusdb.com/)
@@ -139,9 +142,23 @@ AccessControl.prototype.dispatch = function (requestUrl, action, payload) {
139142
action,
140143
payload,
141144
{ type: this.apiType, key: this.apiKey, user: this.user },
145+
null,
146+
this.customHeaders(),
142147
);
143148
};
144149

150+
/**
151+
* add extra headers to your request
152+
* @param {object} customHeaders
153+
* @returns {object}
154+
*/
155+
156+
// eslint-disable-next-line consistent-return
157+
AccessControl.prototype.customHeaders = function (customHeaders) {
158+
if (customHeaders) this._customHeaders = customHeaders;
159+
else return this._customHeaders;
160+
};
161+
145162
/**
146163
* -- TerminusDB API ---
147164
* This end point works in basic authentication, admin user

test/accessControl.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { expect } = require('chai');
2+
const AccessControl = require('../lib/accessControl');
3+
4+
describe('AccessControl tests', () => {
5+
const startServerUrl = 'http://localhost:6363/';
6+
const organization = 'admin';
7+
const user = 'admin';
8+
const key ='mykey'
9+
10+
const accessContol = new AccessControl(startServerUrl,{user,organization,key})
11+
12+
it('check set headers in accessControl', () => {
13+
const customHeaders = { "Custom-header-01":"test-headers", "Custom-header-02": "test"}
14+
accessContol.customHeaders(customHeaders)
15+
expect(accessContol.customHeaders()).to.eql(customHeaders);
16+
})
17+
18+
})

0 commit comments

Comments
 (0)