Skip to content

Commit

Permalink
Do not pass redundant Azure parameters in reg/redeg/checkin body. (#16)
Browse files Browse the repository at this point in the history
* Do not pass redundant Azure parameters in reg/redeg/checkin body.

* Add body into Azure deregister request.
  • Loading branch information
kkuzmin authored Jan 7, 2019
1 parent 7b9daf3 commit f05599a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
33 changes: 22 additions & 11 deletions azcollectc.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,41 @@ class AzcollectC extends AlServiceC {
`${registrationValues.awsAccountId}/${registrationValues.region}/${functionName}`);
}

_doCheckinAzure(checkinBody) {
_doCheckinAzure(checkinInput) {
'use strict';
var checkinBody = Object.assign({}, checkinInput);
const type = this._collectorType;
var functionName = encodeURIComponent(checkinBody.web_app_name);
var checkinUrl = `/azure/${type}/checkin/${checkinBody.subscription_id}/` +
`${checkinBody.app_resource_group}/${functionName}`;
var checkinUrl = `/azure/${type}/checkin/${checkinInput.subscription_id}/` +
`${checkinInput.app_resource_group}/${functionName}`;
delete checkinBody.app_resource_group;
delete checkinBody.subscription_id;
delete checkinBody.web_app_name;
return this._doSendCheckin(checkinUrl, checkinBody);
}

_doRegistrationAzure(regBody) {
_doRegistrationAzure(regInput) {
'use strict';
const collectorType = this._collectorType;
const functionName = encodeURIComponent(regBody.web_app_name);

return this.post(`/azure/${collectorType}/` +
`${regBody.subscription_id}/${regBody.app_resource_group}/${functionName}`, {body: regBody});
var regBody = Object.assign({}, regInput);
const collectorType = this._collectorType;
const functionName = encodeURIComponent(regInput.web_app_name);
delete regBody.app_resource_group;
delete regBody.subscription_id;
delete regBody.web_app_name;
return this.post(`/azure/${collectorType}/` +
`${regInput.subscription_id}/${regInput.app_resource_group}/${functionName}`, {body: regBody});
}

_doDeregistrationAzure(deregBody) {
_doDeregistrationAzure(deregInput) {
'use strict';
var deregBody = Object.assign({}, deregInput);
const collectorType = this._collectorType;
var functionName = encodeURIComponent(deregBody.web_app_name);
delete deregBody.app_resource_group;
delete deregBody.subscription_id;
delete deregBody.web_app_name;
return this.deleteRequest(`/azure/${collectorType}/` +
`${deregBody.subscription_id}/${deregBody.app_resource_group}/${functionName}`);
`${deregInput.subscription_id}/${deregInput.app_resource_group}/${functionName}`, {body: deregBody});
}

_doSendCheckin(checkinUrl, checkinBody) {
Expand Down
39 changes: 30 additions & 9 deletions test/azcollectc_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,22 @@ describe('Unit Tests', function() {
it('Azure register', function(done) {
var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
var azc = new AzcollectC(m_alMock.INGEST_ENDPOINT, aimsc, 'o365');
var expectedChekinBody = {
var expectedRegisterBody = {
body: {
app_resource_group: 'azure-resource-group',
app_tenant_id: 'azure-tenant-id',
client_id: 'azure-client-id',
client_secret: 'azure-client-secret',
config: {
content_streams: '[\"Audit.AzureActiveDirectory\", \"Audit.Exchange\", \"Audit.SharePoint\", \"Audit.General\"]',
type: 'o365'
},
subscription_id: 'azure-subscription-id',
version: '1.0.0',
web_app_name: 'azure-web-app-name'
version: '1.0.0'
}
};

azc.register(m_alMock.AZURE_REGISTER_VALUES).then( resp => {
sinon.assert.calledWith(fakePost, '/azure/o365/azure-subscription-id/azure-resource-group/azure-web-app-name',
expectedChekinBody);
expectedRegisterBody);

done();
});
Expand All @@ -219,12 +216,20 @@ describe('Unit Tests', function() {
const deregValues = {
web_app_name : 'azure-web-app-name',
app_tenant_id : 'azure-tenant-id',
source_id: 'source-id',
app_resource_group : 'azure-resource-group',
subscription_id : 'azure-subscription-id',
};

const expectedDeregBody = {
body: {
app_tenant_id : 'azure-tenant-id',
source_id: 'source-id'
}
};

azc.deregister(deregValues).then( resp => {
sinon.assert.calledWith(fakeDel, '/azure/ehub/azure-subscription-id/azure-resource-group/azure-web-app-name');
sinon.assert.calledWith(fakeDel, '/azure/ehub/azure-subscription-id/azure-resource-group/azure-web-app-name', expectedDeregBody);
done();
});
});
Expand All @@ -233,7 +238,14 @@ describe('Unit Tests', function() {
var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
var azc = new AzcollectC(m_alMock.INGEST_ENDPOINT, aimsc, 'ehub', false);
var expectedCheckinBody = {
body: m_alMock.AZURE_CHECKIN_VALUES
body: {
version : '1.0.0',
app_tenant_id : 'azure-tenant-id',
status: 'ok',
error_code: undefined,
details: [],
statistics: undefined
}
};
azc.checkin(m_alMock.AZURE_CHECKIN_VALUES).then( resp => {
sinon.assert.calledWith(
Expand All @@ -248,7 +260,16 @@ describe('Unit Tests', function() {
var aimsc = new AimsC(m_alMock.AL_API, m_alMock.AIMS_CREDS);
var azc = new AzcollectC(m_alMock.INGEST_ENDPOINT, aimsc, 'ehub', true);

var expectedCompressedBody = zlib.deflateSync(JSON.stringify(m_alMock.AZURE_CHECKIN_VALUES));
var expectedCheckin = {
version : '1.0.0',
app_tenant_id : 'azure-tenant-id',
status: 'ok',
error_code: undefined,
details: [],
statistics: undefined
};

var expectedCompressedBody = zlib.deflateSync(JSON.stringify(expectedCheckin));
var expectedCheckinBody = {
json : false,
headers : {
Expand Down

0 comments on commit f05599a

Please sign in to comment.