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

Update DNS Merchant regular expression length #387

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading