Skip to content
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

Adding schain info #26

Merged
merged 3 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 41 additions & 1 deletion modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ function _createServerRequest(bidRequest, gdprConsent = {}, uspConsent, pageUrl)
} ]
}
};


if(bidRequest.schain) {
ttxRequest.source = _getSchainInfo(bidRequest.schain);
}

// Finally, set the openRTB 'test' param if this is to be a test bid
if (params.test === 1) {
ttxRequest.test = 1;
Expand All @@ -152,6 +156,42 @@ function _createServerRequest(bidRequest, gdprConsent = {}, uspConsent, pageUrl)
}
}

function _getSchainInfo(schain) {
if(_isValidSchain(schain)) {
return {
ext: { schain }
}
} else {
utils.logWarn('[33Across Adapter] Invalid schain info passed');
return null;
}
}

// We validate schain as follows:
// - Complete status must be 0|1
// - Nodes must be defined and non-empty array
// - Each node must contain all the required fields
// The entire schain schain object is marked as invalid i.e. return false if any
// of the above conditions fail.
function _isValidSchain(schain) {
//Check of nodes are valid
if(!schain.nodes || !(schain.nodes.length > 0)) {
return false;
}

//Check is complete status is valid
if(schain.complete !== 0 && schain.complete !== 1) {
return false;
}

// Check for required fields in nodes
const requiredFields = ['asi', 'sid', 'hp'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. I wonder if we need to add this to our validation too for schain nodes.


return schain.nodes.every((node)=> {
return requiredFields.every((field)=> node[field]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does empty string and 0 fail this check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should yes. The values of asi, sid should be a valid string and hp should be 1+.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see, that make sense

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how strictly we want to validate here. But this would pass if hp had any valid string or boolean true value too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right that is true (no pun intended). Hmm I guess this only checks for truthy values. Should we enforce proper validation here?

});
}

// Sync object will always be of type iframe for TTX
function _createSync({ siteId = 'zzz000000000003zzz', gdprConsent = {}, uspConsent }) {
const ttxSettings = config.getConfig('ttxSettings');
Expand Down
125 changes: 125 additions & 0 deletions test/spec/modules/33acrossBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ describe('33acrossBidAdapter:', function () {
return this;
};

this.withSchain = schain => {
Object.assign(ttxRequest, {
source: {
ext: {
schain
}
}
});

return this;
};

this.build = () => ttxRequest;
}

Expand Down Expand Up @@ -589,8 +601,121 @@ describe('33acrossBidAdapter:', function () {
expect(builtServerRequests).to.deep.equal([serverRequest]);
});
});

context('when there is valid schain object in the bidRequest', function() {
it('builds request with schain info in source', function() {
const schain = {
'ver': "1.0",
'complete': 1,
'nodes': [
{
'asi': "bidderA.com",
'sid': "00001",
'hp': 1
}
]
};

bidRequests[0].schain = schain;

const ttxRequest = new TtxRequestBuilder()
.withSchain(schain)
.build();
const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();

const builtServerRequests = spec.buildRequests(bidRequests, {});

expect(builtServerRequests).to.deep.equal([serverRequest]);

});
});

context('when there no schain object is passed', function() {
it('does not set source field', function() {
const ttxRequest = new TtxRequestBuilder()
.build();

const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();

const builtServerRequests = spec.buildRequests(bidRequests, {});

expect(builtServerRequests).to.deep.equal([serverRequest]);
});
});

context('when invalid schain object is passed in the bidRequest', function() {
it('builds request with source set to null', function() {
const invalidSchainValues = [
terryc33x marked this conversation as resolved.
Show resolved Hide resolved
{
'ver': "1.0",
'complete': 1,
},
{
'ver': "1.0",
'complete': 1,
'nodes': []
},
{
'ver': "1.0",
'complete': '1',
'nodes': [
{
'asi': "bidderA.com",
'sid': "00001",
'hp': 1
}
]
},
{
'ver': "1.0",
'complete': 1,
'nodes': [
{
'sid': "00001",
'hp': 1
}
]
},
{
'ver': "1.0",
'complete': 0,
'nodes': [
{
'asi': "",
'sid': "00001",
'hp': 1,
}
]
}
]

invalidSchainValues.forEach((schain)=> {
bidRequests[0].schain = schain;

const ttxRequest = new TtxRequestBuilder()
.withSchain(schain)
.build();

ttxRequest.source = null;

const serverRequest = new ServerRequestBuilder()
.withData(ttxRequest)
.build();


const builtServerRequests = spec.buildRequests(bidRequests, {});

expect(builtServerRequests).to.deep.equal([serverRequest]);
});
});
});
});


describe('interpretResponse', function() {
let ttxRequest, serverRequest;

Expand Down