-
Notifications
You must be signed in to change notification settings - Fork 0
Proxy to masterPod instance if no DNS mapping #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b3ba453
38a6077
9345405
9b8497b
fe94970
d9464a9
c5288a3
6f5fc04
df78307
fe9ef5a
13b6038
19c9319
bf3feab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -368,6 +368,7 @@ describe('api.js unit test', function () { | |
| describe('referer', function () { | ||
| var base = 'api-staging-codenow.runnableapp.com'; | ||
| var req; | ||
|
|
||
| beforeEach(function (done) { | ||
| req = { | ||
| method: 'get', | ||
|
|
@@ -391,16 +392,29 @@ describe('api.js unit test', function () { | |
| sinon.stub(mongo, 'fetchNaviEntry', function (reqUrl, refererUrl, cb) { | ||
| cb(null, naviEntriesFixtures); | ||
| }); | ||
|
|
||
| sinon.stub(api, '_processTargetInstance').yields(); | ||
| sinon.stub(mongo.constructor, 'findAssociationShortHashByElasticUrl').returns(null); | ||
|
|
||
| done(); | ||
| }); | ||
|
|
||
| afterEach(function (done) { | ||
| api._getUrlFromRequest.restore(); | ||
| redis.lrange.restore(); | ||
| mongo.fetchNaviEntry.restore(); | ||
| if (api._processTargetInstance.restore) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason to do the if here. Since the beforeEach will always stub it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is here because some of the methods under test assumed it wasn't stubbed... so some of the tests might have restored it themselves before the afterEach. Not ideal, I know. |
||
| api._processTargetInstance.restore(); | ||
| } | ||
| if (mongo.constructor.findAssociationShortHashByElasticUrl.restore) { | ||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| } | ||
| done(); | ||
| }); | ||
|
|
||
| it('should should ignore referer if same as requestUrl', function (done) { | ||
| api._processTargetInstance.restore(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This unit test should not be calling external libs. This restore is a bad thing here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| req.headers.origin = 'http://'+base; | ||
| api.getTargetHost(req, {}, function (err) { | ||
| expect(err).to.be.undefined(); | ||
|
|
@@ -410,8 +424,9 @@ describe('api.js unit test', function () { | |
| }); | ||
| }); | ||
|
|
||
|
|
||
| it('should proxy to instance mapped by referer naviEntry association', function (done) { | ||
| api._processTargetInstance.restore(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| api.getTargetHost(req, {}, function (err) { | ||
| expect(err).to.be.undefined(); | ||
| // feature-branch1 of API | ||
|
|
@@ -421,6 +436,8 @@ describe('api.js unit test', function () { | |
| }); | ||
|
|
||
| it('should handle navientires document with no user-mappings', function (done) { | ||
| api._processTargetInstance.restore(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| var restore = put({}, naviEntriesFixtures.refererNaviEntry); | ||
| delete naviEntriesFixtures.refererNaviEntry.userMappings; | ||
| api.getTargetHost(req, {}, function (err) { | ||
|
|
@@ -433,6 +450,8 @@ describe('api.js unit test', function () { | |
|
|
||
| it('should next with error if navientries document with no user-mappings and no '+ | ||
| 'masterpod', function (done) { | ||
| api._processTargetInstance.restore(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| var restore = put({}, naviEntriesFixtures.refererNaviEntry); | ||
| delete naviEntriesFixtures.refererNaviEntry.userMappings; | ||
| naviEntriesFixtures.refererNaviEntry.directUrls.aaaaa1.masterPod = false; | ||
|
|
@@ -444,31 +463,37 @@ describe('api.js unit test', function () { | |
| }); | ||
| }); | ||
|
|
||
| it('should next with error if !instanceShortHash', function (done) { | ||
| sinon.stub(mongo.constructor, 'findAssociationShortHashByElasticUrl', function () { | ||
| return null; | ||
| it('should default to masterPod if !instanceShortHash', function (done) { | ||
| var mockNaviEntry = {}; | ||
| sinon.stub(mongo.constructor, 'findMasterPodBranch', function () { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be done with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this stub should be in the forEach. Use Yields instead of passing a function.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed but should we make this into a separate task? We could ship this bug fix with the tests that as Anand points out |
||
| return mockNaviEntry; | ||
| }); | ||
|
|
||
| api.getTargetHost(req, {}, function (err) { | ||
| expect(err.message).to.equal('Not Found'); | ||
| expect(err).to.be.undefined(); | ||
| sinon.assert.calledWith(api._processTargetInstance, mockNaviEntry); | ||
| expect(mongo.constructor.findAssociationShortHashByElasticUrl.callCount).to.equal(1); | ||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| mongo.constructor.findMasterPodBranch.restore(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore should only be done in afterEach. |
||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should default to masterPod instance if assocation not in requestUrl directUrls', | ||
| function (done) { | ||
| sinon.stub(mongo.constructor, 'findAssociationShortHashByElasticUrl', function () { | ||
| return 'FFFFF'; //This is an instance not defined in requestUrl directUrls | ||
| }); | ||
| sinon.stub(api, '_processTargetInstance', | ||
| function (targetNaviEntryInstance, reqUrl, req, next) { | ||
| expect(targetNaviEntryInstance.masterPod).to.equal(true); | ||
| mongo.constructor.findAssociationShortHashByElasticUrl.restore(); | ||
| api._processTargetInstance.restore(); | ||
| next(); | ||
| it('should default to masterPod instance if no associations/dns-mappings defined', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's really weird to stub when not in a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many of these tests need to stub these methods to return different values, which I can't really do cleanly in a beforeEach
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you need to stub it for different values you can stub it in one spot and then just do
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 I have used that pattern a lot
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good I'll do that from now on
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this into a beforeEach/afterEach
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test has zero assertions. |
||
| function (done) { | ||
|
|
||
| sinon.stub(mongo.constructor, 'findMasterPodBranch'); | ||
| mongo.constructor.findMasterPodBranch.onFirstCall().returns({}); | ||
| mongo.constructor.findMasterPodBranch.onSecondCall().returns(undefined); | ||
| mongo.constructor.findMasterPodBranch.onThirdCall().returns({ | ||
| masterPod: true | ||
| }); | ||
|
|
||
| api.getTargetHost(req, {}, function () { | ||
| sinon.assert.calledWith(api._processTargetInstance, sinon.match({ | ||
| masterPod: true | ||
| })); | ||
| sinon.assert.calledWith(api._processTargetInstance) | ||
| mongo.constructor.findMasterPodBranch.restore(); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I have a referer coming from an instance that is destroyed, aka the user has not refreshed the page. Do we need to handle this?