File tree Expand file tree Collapse file tree 2 files changed +31
-11
lines changed
Expand file tree Collapse file tree 2 files changed +31
-11
lines changed Original file line number Diff line number Diff line change @@ -41,8 +41,7 @@ describe('parseMinioDSN', () => {
4141 } )
4242 } )
4343
44- // TODO: fix this
45- it . skip ( 'correctly parses a minio DSN with https' , ( ) => {
44+ it ( 'correctly parses a minio DSN with https' , ( ) => {
4645 const dsn = parseMinioDSN ( 'https://my-minio.example.com:443' )
4746
4847 expect ( dsn ) . toEqual ( {
@@ -52,8 +51,24 @@ describe('parseMinioDSN', () => {
5251 } )
5352 } )
5453
55- it ( 'throws an error if port is missing' , ( ) => {
56- expect ( ( ) => parseMinioDSN ( 'https://my-minio.example.com' ) ) . toThrow ( 'Invalid Minio DSN' )
54+ it ( 'correctly parses a minio DSN with https and standard port' , ( ) => {
55+ const dsn = parseMinioDSN ( 'https://my-minio.example.com' )
56+
57+ expect ( dsn ) . toEqual ( {
58+ endPoint : 'my-minio.example.com' ,
59+ port : 443 ,
60+ useSSL : true ,
61+ } )
62+ } )
63+
64+ it ( 'correctly parses a minio DSN with http and standard port' , ( ) => {
65+ const dsn = parseMinioDSN ( 'http://my-minio.example.com' )
66+
67+ expect ( dsn ) . toEqual ( {
68+ endPoint : 'my-minio.example.com' ,
69+ port : 80 ,
70+ useSSL : false ,
71+ } )
5772 } )
5873
5974 it ( 'throws an error if hostname is missing' , ( ) => {
Original file line number Diff line number Diff line change @@ -11,19 +11,24 @@ interface MinioConnectionOptions {
1111}
1212
1313export function parseMinioDSN ( dsn : string ) : MinioConnectionOptions {
14+ const HTTPS_DEFAULT_PORT = 443
15+ const HTTP_DEFAULT_PORT = 80
16+
1417 const url = new URL ( dsn )
1518
1619 const endPoint = url . hostname
17- const port = Number ( url . port )
1820 const useSSL = url . protocol === 'https:'
1921
20- if ( ! port || ! endPoint ) {
21- throw new Error ( 'Invalid Minio DSN' )
22+ let port = Number ( url . port )
23+
24+ // Cannot obtain port (0 or NaN), fill with default port of protocol
25+ if ( port === 0 ) {
26+ port = useSSL ? HTTPS_DEFAULT_PORT : HTTP_DEFAULT_PORT
2227 }
2328
24- return {
25- endPoint,
26- port,
27- useSSL,
29+ if ( ! endPoint ) {
30+ throw new Error ( 'Invalid Minio DSN' )
2831 }
32+
33+ return { endPoint, port, useSSL }
2934}
You can’t perform that action at this time.
0 commit comments