Skip to content
This repository was archived by the owner on Dec 12, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/resource/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,4 +1503,17 @@ Application.prototype.getAccountLinkingPolicy = function getApplicationAccountLi
return this.dataStore.getResource(this.accountLinkingPolicy.href, args.options, require('./AccountLinkingPolicy'), args.callback);
};

/**
* Retrieves the application's {@link WebConfig}, which determines its behaviour
* regarding the Client API.
*
* @param {Function} callback
* The function that will be called when the query is finished, with the parameters
* (err, {@link WebConfig}).
*/
Application.prototype.getWebConfig = function getApplicationWebConfig(/* callback */) {
var args = utils.resolveArgs(arguments, ['callback'], true);
return this.dataStore.getResource(this.webConfig.href, null, require('./WebConfig'), args.callback);
};

module.exports = Application;
78 changes: 78 additions & 0 deletions lib/resource/WebConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
'use strict';

var InstanceResource = require('./InstanceResource');
var utils = require('../utils');

/**
* @class WebConfig
*
* @augments {InstanceResource}
*
* @description
*
* Encapsulates a WebConfig resource, which determines the behaviour of the
* web application used for the Client API. For full documentation of this
* resource, please see
* [Configuring the Client API](https://docs.stormpath.com/client-api/product-guide/latest/configuration.html).
*
* This class should not be manually constructed. It should be obtained from one
* of these methods:
*
* - {@link Application#getWebConfig Application.getWebConfig()}.
*
* @param {Object} webConfigResource
*
* The JSON representation of this resource.
*/
function WebConfig() {
WebConfig.super_.apply(this, arguments);
}

utils.inherits(WebConfig, InstanceResource);

/**
* Retrieves the {@link Application} that this web configuration is attached to.
*
* @param {ExpansionOptions} options
* Options for retrieving the linked resources of the application.
*
* @param {Function} callback
* The function to call after the query has completed. It will be called with
* (err, {@link Application}).
*/
WebConfig.prototype.getApplication = function getWebConfigApplication(/* [options], callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.application.href, args.options, require('./Application'), args.callback);
};

/**
* Retrieves the {@link ApiKey} that this web config is using for signing tokens.
*
* @param {Options} options
* Options for retrieving the linked resources of the API Key.
*
* @param {Function} callback
* The function to call after the query has completed. It will be called with
* (err, {@link ApiKey}).
*/
WebConfig.prototype.getSigningApiKey = function getSigningApiKey(/* [options], callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.signingApiKey.href, args.options, require('./ApiKey'), args.callback);
};

/**
* Retrieves the {@link Tenant} for this web configuration.
*
* @param {ExpansionOptions} options
* Options for retrieving the linked resources of the tenant.
*
* @param {Function} callback
* The function to call after the query has completed. It will be called with
* (err, {@link Tenant}).
*/
WebConfig.prototype.getTenant = function getWebConfigTenant(/* [options], callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.tenant.href, args.options, require('./Tenant'), args.callback);
};

module.exports = WebConfig;
97 changes: 97 additions & 0 deletions test/it/web_config_it.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use strict';

var common = require('../common');
var helpers = require('./helpers');
var assert = common.assert;

var WebConfig = require('../../lib/resource/WebConfig');

describe('WebConfig', function() {
var client;
var app;
var webConfig;
var signingKey;

before(function(done) {
helpers.getClient(function(_client) {
client = _client;
signingKey = client._dataStore.requestExecutor.options.client.apiKey.secret;

client.createApplication({ name: helpers.uniqId()}, function(err, _app) {
if (err) {
return done(err);
}

app = _app;
app.getWebConfig(function(err, _webConfig) {
if (err) {
return done(err);
}

webConfig = _webConfig;
done();
});
});
});
});

after(function(done) {
app.delete(function(err) {
if (err) {
return done(err);
}

done();
});
});

it('should be get-able', function() {
assert.instanceOf(webConfig, WebConfig);
});

it('should have the application uri', function() {
assert.isOk(webConfig.dnsLabel);
});

it('should be possible to enable it', function(done) {
webConfig.status = 'ENABLED';

webConfig.save(function(err, _webConfig) {
if (err) {
return done(err);
}

assert.equal(_webConfig.status, 'ENABLED');
done();
});
});

it('should be possible to disable it', function(done) {
webConfig.status = 'DISABLED';

webConfig.save(function(err, _webConfig) {
if (err) {
return done(err);
}

assert.equal(_webConfig.status, 'DISABLED');
done();
});
});

it('should be possible to edit it', function(done) {
var oldRegisterStatus = webConfig.register.enabled;
var newRegisterStatus = !oldRegisterStatus;

webConfig.register.enabled = newRegisterStatus;

webConfig.save(function(err, _webConfig) {
if (err) {
return done(err);
}

assert.equal(_webConfig.register.enabled, newRegisterStatus);
done();
});
});
});
35 changes: 35 additions & 0 deletions test/sp.resource.application_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var ApiKey = require('../lib/resource/ApiKey');
var DataStore = require('../lib/ds/DataStore');
var PasswordResetToken = require('../lib/resource/PasswordResetToken');
var AccountLinkingPolicy = require('../lib/resource/AccountLinkingPolicy');
var WebConfig = require('../lib/resource/WebConfig');
var nJwt = require('njwt');
var nJwtProperties = require('njwt/properties');
var uuid = require('uuid');
Expand Down Expand Up @@ -1501,5 +1502,39 @@ describe('Resources: ', function () {
});
});

describe('get web config', function () {
var sandbox, application, getResourceStub, cbSpy, app;
before(function () {
sandbox = sinon.sandbox.create();
app = {
webConfig: {
href: 'boom!'
}
};

application = new Application(app, dataStore);
getResourceStub = sandbox.stub(dataStore, 'getResource', function (href, options, ctor, cb) {
cb();
});
cbSpy = sandbox.spy();

application.getWebConfig(cbSpy);
});

after(function () {
sandbox.restore();
});

it('should get the web config', function () {
/* jshint -W030 */
getResourceStub.should.have.been.calledOnce;
cbSpy.should.have.been.calledOnce;
/* jshint +W030 */

getResourceStub.should.have.been
.calledWith(app.webConfig.href, null, WebConfig, cbSpy);
});
});

});
});
Loading