From 13ef86e3456476698f2ab4d6e1198293c41d435a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Thu, 29 Aug 2024 14:00:47 +0200 Subject: [PATCH] Update DNS Merchant regular expression length (#387) --- src/Checkout.js | 2 +- test/config/config.js | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Checkout.js b/src/Checkout.js index 55e56c9..80e64e4 100644 --- a/src/Checkout.js +++ b/src/Checkout.js @@ -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); } diff --git a/test/config/config.js b/test/config/config.js index 6e7f86f..ff16e0f 100644 --- a/test/config/config.js +++ b/test/config/config.js @@ -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; @@ -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');