Skip to content

Commit f7e7ddc

Browse files
author
Joe Goggins
committed
Move call to _getEffectiveAuth to agent forwarders
This should be exhaustive; any API method that includes an http auth parameter should pass it through to the agent
1 parent fc70170 commit f7e7ddc

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

src/Particle.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,6 @@ class Particle {
411411
uri = '/v1/devices';
412412
}
413413

414-
auth = this._getEffectiveAuth(auth);
415414
return this.get({ uri, auth, headers, query, context });
416415
}
417416

@@ -2141,31 +2140,37 @@ class Particle {
21412140

21422141
get({ uri, auth, headers, query, context }){
21432142
context = this._buildContext(context);
2143+
auth = this._getEffectiveAuth(auth);
21442144
return this.agent.get({ uri, auth, headers, query, context });
21452145
}
21462146

21472147
head({ uri, auth, headers, query, context }){
21482148
context = this._buildContext(context);
2149+
auth = this._getEffectiveAuth(auth);
21492150
return this.agent.head({ uri, auth, headers, query, context });
21502151
}
21512152

21522153
post({ uri, auth, headers, data, context }){
21532154
context = this._buildContext(context);
2155+
auth = this._getEffectiveAuth(auth);
21542156
return this.agent.post({ uri, auth, headers, data, context });
21552157
}
21562158

21572159
put({ uri, auth, headers, data, context }){
21582160
context = this._buildContext(context);
2161+
auth = this._getEffectiveAuth(auth);
21592162
return this.agent.put({ uri, auth, headers, data, context });
21602163
}
21612164

21622165
delete({ uri, auth, headers, data, context }){
21632166
context = this._buildContext(context);
2167+
auth = this._getEffectiveAuth(auth);
21642168
return this.agent.delete({ uri, auth, headers, data, context });
21652169
}
21662170

21672171
request(args){
21682172
args.context = this._buildContext(args.context);
2173+
args.auth = this._getEffectiveAuth(args.auth);
21692174
return this.agent.request(args);
21702175
}
21712176

test/Particle.spec.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,18 +388,6 @@ describe('ParticleAPI', () => {
388388
});
389389

390390
describe('.listDevices', () => {
391-
describe('uses effective auth', () => {
392-
afterEach(() => {
393-
sinon.restore();
394-
});
395-
it('calls this._getEffectiveAuth', async () => {
396-
sinon.stub(api, '_getEffectiveAuth');
397-
sinon.stub(api, 'get'); // don't actually call the real method
398-
await api.listDevices(props);
399-
expect(api._getEffectiveAuth).to.have.property('callCount', 1);
400-
});
401-
});
402-
403391
describe('user scope', () => {
404392
it('generates request', () => {
405393
return api.listDevices(props).then((results) => {
@@ -2648,13 +2636,15 @@ describe('ParticleAPI', () => {
26482636
contextResult = { def: 456 };
26492637
result = 'fake-result';
26502638
api._buildContext = sinon.stub().returns(contextResult);
2639+
api._getEffectiveAuth = sinon.stub().returns(auth);
26512640
});
26522641

26532642
afterEach(() => {
26542643
expect(api._buildContext).to.have.been.calledWith(context);
2644+
expect(api._getEffectiveAuth).to.have.been.calledWith(auth);
26552645
});
26562646

2657-
it('calls _buildContext from get', () => {
2647+
it('calls _buildContext and _getEffectiveAuth from get', () => {
26582648
api.agent.get = sinon.stub().returns(result);
26592649
const options = { uri, auth, headers, query, context };
26602650
const res = api.get(options);
@@ -2668,7 +2658,7 @@ describe('ParticleAPI', () => {
26682658
});
26692659
});
26702660

2671-
it('calls _buildContext from head', () => {
2661+
it('calls _buildContext and _getEffectiveAuth from head', () => {
26722662
api.agent.head = sinon.stub().returns(result);
26732663
const options = { uri, auth, headers, query, context };
26742664
const res = api.head(options);
@@ -2682,7 +2672,7 @@ describe('ParticleAPI', () => {
26822672
});
26832673
});
26842674

2685-
it('calls _buildContext from post', () => {
2675+
it('calls _buildContext and _getEffectiveAuth from post', () => {
26862676
api.agent.post = sinon.stub().returns(result);
26872677
const options = { uri, auth, headers, data, context };
26882678
const res = api.post(options);
@@ -2696,7 +2686,7 @@ describe('ParticleAPI', () => {
26962686
});
26972687
});
26982688

2699-
it('calls _buildContext from put', () => {
2689+
it('calls _buildContext and _getEffectiveAuth from put', () => {
27002690
api.agent.put = sinon.stub().returns(result);
27012691
const options = { uri, auth, headers, data, context };
27022692
const res = api.put(options);
@@ -2710,7 +2700,7 @@ describe('ParticleAPI', () => {
27102700
});
27112701
});
27122702

2713-
it('calls _buildContext from delete', () => {
2703+
it('calls _buildContext and _getEffectiveAuth from delete', () => {
27142704
api.agent.delete = sinon.stub().returns(result);
27152705
const options = { uri, auth, headers, data, context };
27162706
const res = api.delete(options);
@@ -2724,10 +2714,10 @@ describe('ParticleAPI', () => {
27242714
});
27252715
});
27262716

2727-
it('calls _buildContext from request', () => {
2717+
it('calls _buildContext and _getEffectiveAuth from request', () => {
27282718
api.agent.request = sinon.stub().returns(result);
2729-
api.request({ context }).should.eql(result);
2730-
expect(api.agent.request).to.have.been.calledWith({ context:contextResult });
2719+
api.request({ context, auth }).should.eql(result);
2720+
expect(api.agent.request).to.have.been.calledWith({ context:contextResult, auth });
27312721
});
27322722
});
27332723
});

0 commit comments

Comments
 (0)