Skip to content

Commit

Permalink
Update DNS Merchant regular expression length (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko authored Aug 29, 2024
1 parent b646f6b commit 13ef86e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const determineUrl = (environment, options) => {

if (options && options.subdomain) {
const subdomain = options.subdomain;
if (typeof subdomain === 'string' && /^[0-9a-z]{8,11}$/.test(subdomain)) {
if (typeof subdomain === 'string' && /^[0-9a-z]+$/.test(subdomain)) {
const { protocol, port, hostname } = apiUrl;
return new URL(`${protocol}//${subdomain}.${hostname}${port ? `:${port}` : ''}`).toString().slice(0, -1);
}
Expand Down
23 changes: 19 additions & 4 deletions test/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,31 @@ describe('NAS oAuth', () => {
expect(cko.config.agent).to.be.undefined;
});

it('should initialize with oAuth credentials with subdomain', () => {
it('should initialize with oAuth credentials with short subdomain', () => {
const cko = new Checkout('2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-', {
client: 'ack_vvzhoai466su3j3vbxb47ts5oe',
scope: ['gateway'],
environment: 'sandbox',
subdomain: '12345domain'
subdomain: 'ab'
});
expect(cko).to.be.instanceOf(Checkout);
expect(cko.config.client).to.equal('ack_vvzhoai466su3j3vbxb47ts5oe');
expect(cko.config.host).to.equal('https://12345domain.api.sandbox.checkout.com');
expect(cko.config.host).to.equal('https://ab.api.sandbox.checkout.com');
expect(cko.config.scope[0]).to.equal('gateway');
expect(cko.config.secret).to.equal('2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-');
expect(cko.config.agent).to.be.undefined;
});

it('should initialize with oAuth credentials with long subdomain', () => {
const cko = new Checkout('2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-', {
client: 'ack_vvzhoai466su3j3vbxb47ts5oe',
scope: ['gateway'],
environment: 'sandbox',
subdomain: 'longsubdomain'
});
expect(cko).to.be.instanceOf(Checkout);
expect(cko.config.client).to.equal('ack_vvzhoai466su3j3vbxb47ts5oe');
expect(cko.config.host).to.equal('https://longsubdomain.api.sandbox.checkout.com');
expect(cko.config.scope[0]).to.equal('gateway');
expect(cko.config.secret).to.equal('2p7YQ37fHiRr8O6lQAikl8enICesB1dvAJrpmE2nZfEOpxzE-');
expect(cko.config.agent).to.be.undefined;
Expand All @@ -159,7 +174,7 @@ describe('NAS oAuth', () => {
client: 'ack_vvzhoai466su3j3vbxb47ts5oe',
scope: ['gateway'],
environment: 'sandbox',
subdomain: '12345domain12345'
subdomain: ' '
});
expect(cko).to.be.instanceOf(Checkout);
expect(cko.config.client).to.equal('ack_vvzhoai466su3j3vbxb47ts5oe');
Expand Down

0 comments on commit 13ef86e

Please sign in to comment.