Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 2414d22

Browse files
[ACS-4724] remove minimatch dependency (#1536)
* ACS-4724 Removed minimatch dependency * ACS-4724 Updated package-lock json file
1 parent a7c0cee commit 2414d22

File tree

8 files changed

+128
-58
lines changed

8 files changed

+128
-58
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ With this authentication the ticket is not validated against the server
191191

192192
// Login with ECM ticket
193193
const alfrescoApi = new AlfrescoApi({
194-
ticketEcm:'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
194+
ticketEcm:'TICKET_4479f4d3bb155195879bfbb8d5206f433488a1b1',
195195
hostEcm:'http://127.0.0.1:8080'
196196
});
197197

@@ -247,7 +247,7 @@ redirectLogout| url to be redirect after logout optional, if is nor present the
247247
refreshTokenTimeout| millisecond value, after how many millisecond you want refresh the token| 30000|
248248
redirectSilentIframeUri| url to be redirect after silent refresh login| /assets/silent-refresh.html |
249249
silentLogin| direct execute the implicit login without the need to call AlfrescoJsApi.implicitLogin() method| false|
250-
publicUrls | list of public urls that don't need authorization. It is possible too pass absolute paths and string patterns that are valid for [minimatch](https://github.com/isaacs/minimatch#readme) |
250+
publicUrls | list of public urls that don't need authorization. It is possible too pass absolute paths and string patterns. In patterns you can use * or ** wildcards. Single means that you can have anything in one part of URL for example http://some-public-url/path/* matches with http://some-public-url/path/test. Double means that you can have anything in any number of parts, for example http://some-public-url/path/** matches with http://some-public-url/path/test/some-test.|
251251
authorizationUrl| authorization url, relative to the host| /protocol/openid-connect/auth|
252252
tokenUrl| token url, relative to the host| /protocol/openid-connect/token|
253253
logoutUrl| logout url, relative to the host| /protocol/openid-connect/logout|
@@ -358,7 +358,7 @@ logout()
358358
alfrescoJsApi.logout().then(
359359
data => {
360360
console.log('Successfully Logout');
361-
},
361+
},
362362
error => {
363363
console.error('Possible ticket already expired');
364364
}
@@ -527,7 +527,7 @@ alfrescoJsApi.nodes
527527
.then(
528528
data => {
529529
console.log('This is the name' + data.name );
530-
},
530+
},
531531
error => {
532532
console.log('This node does not exist');
533533
}

docs/licences/license-info-5.1.0.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ This page lists all third party libraries the project depends on.
3838
| [mime-db](https://github.com/jshttp/mime-db) | 1.40.0 | [MIT](http://www.opensource.org/licenses/MIT) |
3939
| [mime-types](https://github.com/jshttp/mime-types) | 2.1.24 | [MIT](http://www.opensource.org/licenses/MIT) |
4040
| [mime](https://github.com/broofa/mime) | 2.6.0 | [MIT](http://www.opensource.org/licenses/MIT) |
41-
| [minimatch](https://github.com/isaacs/minimatch) | 5.0.1 | [ISC](https://www.isc.org/downloads/software-support-policy/isc-license/) |
4241
| [ms](https://github.com/zeit/ms) | 2.1.2 | [MIT](http://www.opensource.org/licenses/MIT) |
4342
| [next-tick](https://github.com/medikoo/next-tick) | 1.0.0 | [MIT](http://www.opensource.org/licenses/MIT) |
4443
| [object-inspect](https://github.com/inspect-js/object-inspect) | 1.12.0 | [MIT](http://www.opensource.org/licenses/MIT) |

package-lock.json

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@
3333
},
3434
"dependencies": {
3535
"event-emitter": "^0.3.5",
36-
"minimatch": "7.2.0",
3736
"superagent": "^6.0.0",
3837
"tslib": "^2.0.0"
3938
},
4039
"devDependencies": {
4140
"@types/chai": "^4.2.3",
4241
"@types/event-emitter": "^0.3.3",
43-
"@types/minimatch": "^3.0.3",
4442
"@types/mocha": "^10.0.1",
4543
"@types/node": "^18.13.0",
4644
"@types/sinon": "^10.0.1",

src/authentication/oauth2Auth.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ import { AuthenticationApi } from '../api/auth-rest-api/api/authentication.api';
2323
import { AlfrescoApi } from '../alfrescoApi';
2424
import { Storage } from '../storage';
2525
import { HttpClient } from '../api-clients/http-client.interface';
26+
import { PathMatcher } from '../utils/path-matcher';
2627

2728
declare const Buffer: any;
28-
declare const require: any;
29-
// tslint:disable-next-line
30-
const minimatch = require('minimatch');
3129

3230
declare let window: Window;
3331

@@ -228,7 +226,7 @@ export class Oauth2Auth extends AlfrescoApiClient {
228226

229227
if (Array.isArray(publicUrls)) {
230228
return publicUrls.length > 0 &&
231-
publicUrls.some((urlPattern: string) => minimatch(window.location.href, urlPattern));
229+
publicUrls.some((urlPattern: string) => PathMatcher.match(window.location.href, urlPattern));
232230
}
233231
return false;
234232
}

src/utils/path-matcher.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export class PathMatcher {
2+
static match(path: string, pattern: string) {
3+
return new RegExp(
4+
`^${
5+
pattern
6+
.replace(/(^|[^\*])\*(?!\*)/g, '$1([^\\/]*)')
7+
.replace(/\/\*\*\//g, '/(.+)/|/')
8+
.replace(/\*\*/g, '(.*)')
9+
}$`
10+
).test(path);
11+
}
12+
}

test/oauth2Auth.spec.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const spies = require('chai-spies');
1010
chai.use(spies);
1111

1212
import { EcmAuthMock, OAuthMock } from '../test/mockObjects';
13+
import { PathMatcher } from '../src/utils/path-matcher';
1314

1415
const jsdom = require('mocha-jsdom');
1516
const globalAny: any = global;
@@ -546,53 +547,54 @@ describe('Oauth2 test', () => {
546547
);
547548
});
548549

549-
it('should return `true` if url is defined in public urls list', () => {
550+
it('should return true if PathMatcher.match returns true for matching url', () => {
550551
globalAny.window = { location: { href: 'public-url' } };
551552
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
553+
chai.spy.on(PathMatcher, 'match', () => true);
552554

553-
expect(oauth2Auth.isPublicUrl()).to.be.equal(true);
555+
expect(oauth2Auth.isPublicUrl()).be.true;
556+
expect(PathMatcher.match).called.with(globalAny.window.location.href, oauth2Auth.config.oauth2.publicUrls[0]);
554557
});
555558

556-
it('should return `false` if url is not defined in public urls list', () => {
559+
it('should return false if PathMatcher.match returns false for matching url', () => {
557560
globalAny.window = { location: { href: 'some-public-url' } };
558561
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
562+
chai.spy.on(PathMatcher, 'match', () => false);
559563

560-
expect(oauth2Auth.isPublicUrl()).to.be.equal(false);
564+
expect(oauth2Auth.isPublicUrl()).be.false;
565+
expect(PathMatcher.match).called.with(globalAny.window.location.href, oauth2Auth.config.oauth2.publicUrls[0]);
561566
});
562567

563-
it('should return `false` if publicUrls property is not defined', () => {
564-
expect(oauth2Auth.isPublicUrl()).to.be.equal(false);
568+
it('should return false if publicUrls property is not defined', () => {
569+
chai.spy.on(PathMatcher, 'match');
570+
571+
expect(oauth2Auth.isPublicUrl()).be.false;
572+
expect(PathMatcher.match).not.called();
565573
});
566574

567-
it('should return `false` if public urls is not set as an array list', () => {
575+
it('should return false if public urls is not set as an array list', () => {
568576
globalAny.window = { location: { href: 'public-url-string' } };
569577
oauth2Auth.config.oauth2.publicUrls = null;
578+
chai.spy.on(PathMatcher, 'match');
570579

571-
expect(oauth2Auth.isPublicUrl()).to.be.equal(false);
572-
});
573-
574-
it('should match absolute path', () => {
575-
globalAny.window = { location: { href: 'http://some-public-url' } };
576-
oauth2Auth.config.oauth2.publicUrls = ['http://some-public-url'];
577-
578-
expect(oauth2Auth.isPublicUrl()).to.be.equal(true);
579-
});
580-
581-
it('should match a path pattern', () => {
582-
globalAny.window = { location: { href: 'http://some-public-url/123/path' } };
583-
oauth2Auth.config.oauth2.publicUrls = ['**/some-public-url/*/path'];
584-
585-
expect(oauth2Auth.isPublicUrl()).to.be.equal(true);
580+
expect(oauth2Auth.isPublicUrl()).be.false;
581+
expect(PathMatcher.match).not.called();
586582
});
587583

588584
it('should not call `implicitLogin`', async () => {
589585
globalAny.window = { location: { href: 'public-url' } };
590586
oauth2Auth.config.oauth2.silentLogin = true;
591587
oauth2Auth.config.oauth2.publicUrls = ['public-url'];
588+
chai.spy.on(PathMatcher, 'match', () => true);
592589
const implicitLoginSpy = chai.spy.on(oauth2Auth, 'implicitLogin');
593590

594591
await oauth2Auth.checkFragment();
595592
expect(implicitLoginSpy).not.to.have.been.called();
593+
expect(PathMatcher.match).called.with(globalAny.window.location.href, oauth2Auth.config.oauth2.publicUrls[0]);
594+
});
595+
596+
afterEach(() => {
597+
chai.spy.restore(PathMatcher, 'match');
596598
});
597599
});
598600
});

test/path-matcher.spec.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { PathMatcher } from '../src/utils/path-matcher';
2+
3+
const chai = require('chai');
4+
const expect = chai.expect;
5+
6+
describe('PathMatcher', () => {
7+
describe('match', () => {
8+
it('should return true if path is exactly the same like pattern', () => {
9+
expect(PathMatcher.match('public-url', 'public-url')).be.true;
10+
});
11+
12+
it('should return false if path is not equal to pattern', () => {
13+
expect(PathMatcher.match('some-public-url', 'public-url')).be.false;
14+
});
15+
16+
it('should return true if absolute path is equal to absolute path', () => {
17+
expect(PathMatcher.match('http://some-public-url', 'http://some-public-url')).be.true;
18+
});
19+
20+
it('should return true if path matches pattern containing double and single *', () => {
21+
expect(PathMatcher.match('http://some-public-url/123/path', '**/some-public-url/*/path')).be.true;
22+
});
23+
24+
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => {
25+
expect(PathMatcher.match('http://test/other-test/some-public-url/path', '**/some-public-url/path')).be.true;
26+
});
27+
28+
it('should return true if path matches to pattern after replacing ** with multiple parts at the beginning', () => {
29+
expect(PathMatcher.match('http://test/other-test/some-public-url/path', '**/some-public-url/path')).be.true;
30+
});
31+
32+
it('should return true if path matches to pattern after replacing ** with multiple parts at the end', () => {
33+
expect(PathMatcher.match('http://some-public-url/path/test/other-test', 'http://some-public-url/path/**')).be.true;
34+
});
35+
36+
it('should return true if path matches to pattern after replacing ** with none parts at the end', () => {
37+
expect(PathMatcher.match('http://some-public-url/path/', 'http://some-public-url/path/**')).be.true;
38+
});
39+
40+
it('should return false if path does not match to pattern after replacing ** with none parts at the end and cuts last /', () => {
41+
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/path/**')).be.false;
42+
});
43+
44+
it('should return true if path matches to pattern after replacing ** with multiple parts in the middle', () => {
45+
expect(PathMatcher.match('http://some-public-url/test/other-test/path', 'http://some-public-url/**/path')).be.true;
46+
});
47+
48+
it('should return true if path matches to pattern after replacing ** with none parts in the middle', () => {
49+
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/**/path')).be.true;
50+
});
51+
52+
it('should return false if path does not match to pattern with **', () => {
53+
expect(PathMatcher.match('http://some-public-url/', 'http://some-public-url/**/path')).be.false;
54+
});
55+
56+
it('should return false if path has more than one part as replacement for * in the middle of pattern', () => {
57+
expect(PathMatcher.match('http://some-public-url/123/test/path', 'http://some-public-url/*/path')).be.false;
58+
});
59+
60+
it('should return false if path has zero parts as replacement for * in the middle of pattern', () => {
61+
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/*/path')).be.false;
62+
});
63+
64+
it('should return true if path matches to pattern containing * at the end', () => {
65+
expect(PathMatcher.match('http://some-public-url/path/test', 'http://some-public-url/path/*')).be.true;
66+
});
67+
68+
it('should return false if path matches to pattern containing * at the end and cuts last /', () => {
69+
expect(PathMatcher.match('http://some-public-url/path', 'http://some-public-url/path/*')).be.false;
70+
});
71+
72+
it('should return false if path has more than one part as replacement for * at the end of pattern', () => {
73+
expect(PathMatcher.match('http://some-public-url/path/test/other-test', 'http://some-public-url/path/*')).be.false;
74+
});
75+
76+
it('should return false if path has zero parts as replacement for * at the end of pattern', () => {
77+
expect(PathMatcher.match('http://some-public-url/path/test/other-test', 'http://some-public-url/path/*')).be.false;
78+
});
79+
80+
it('should return false if path starts with http:// and * is at the beginning of pattern', () => {
81+
expect(PathMatcher.match('http://some-public-url/path/test', '*/some-public-url/path')).be.false;
82+
});
83+
});
84+
});

0 commit comments

Comments
 (0)