@@ -15,7 +15,7 @@ import jwt from 'jsonwebtoken';
15
15
import { env , includes } from '@salesforce/kit' ;
16
16
import { spyMethod , stubMethod } from '@salesforce/ts-sinon' ;
17
17
import { AnyJson , getJsonMap , JsonMap , toJsonMap } from '@salesforce/ts-types' ;
18
- import { expect } from 'chai' ;
18
+ import { expect , config as chaiConfig } from 'chai' ;
19
19
import { Transport } from '@jsforce/jsforce-node/lib/transport' ;
20
20
21
21
import { OAuth2 } from '@jsforce/jsforce-node' ;
@@ -34,6 +34,7 @@ import { SfdcUrl } from '../../../src/util/sfdcUrl';
34
34
import * as suggestion from '../../../src/util/findSuggestion' ;
35
35
import { SfError } from '../../../src' ;
36
36
37
+ chaiConfig . truncateThreshold = 0 ;
37
38
class AuthInfoMockOrg extends MockTestOrgData {
38
39
public privateKey = 'authInfoTest/jwt/server.key' ;
39
40
public expirationDate = '12-02-20' ;
@@ -1273,13 +1274,15 @@ describe('AuthInfo', () => {
1273
1274
) ;
1274
1275
} ) ;
1275
1276
1276
- it ( 'should handle undefined client secret ' , async ( ) => {
1277
+ it ( 'should handle instance url with a port on it ' , async ( ) => {
1277
1278
stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'determineIfDevHub' ) . resolves ( false ) ;
1278
1279
stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'getNamespacePrefix' ) . resolves ( ) ;
1279
1280
1281
+ const url = new URL ( `${ testOrg . instanceUrl } :6101` ) ;
1282
+
1280
1283
const authResponse = {
1281
1284
access_token : testOrg . accessToken ,
1282
- instance_url : testOrg . instanceUrl ,
1285
+ instance_url : url . toString ( ) ,
1283
1286
id : '00DAuthInfoTest_orgId/005AuthInfoTest_userId' ,
1284
1287
} ;
1285
1288
@@ -1291,17 +1294,17 @@ describe('AuthInfo', () => {
1291
1294
username : testOrg . username ,
1292
1295
oauth2Options : {
1293
1296
refreshToken : testOrg . refreshToken ,
1294
- loginUrl : testOrg . loginUrl ,
1297
+ loginUrl : url . toString ( ) ,
1295
1298
} ,
1296
1299
} ) ;
1297
1300
1298
- // delete the client secret
1299
- authInfo . update ( { clientSecret : undefined } ) ;
1300
- const instanceUrl = testOrg . instanceUrl . replace ( 'https://' , '' ) ;
1301
- expect ( authInfo . getSfdxAuthUrl ( ) ) . to . contain ( `force://PlatformCLI:: ${ testOrg . refreshToken } @ ${ instanceUrl } ` ) ;
1301
+ // host will include the port
1302
+ const result = authInfo . getSfdxAuthUrl ( ) ;
1303
+ expect ( result ) . to . contain ( url . port ) ;
1304
+ expect ( result ) . to . contain ( url . host ) ;
1302
1305
} ) ;
1303
1306
1304
- it ( 'should handle undefined refresh token ' , async ( ) => {
1307
+ it ( 'should handle undefined client secret ' , async ( ) => {
1305
1308
stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'determineIfDevHub' ) . resolves ( false ) ;
1306
1309
stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'getNamespacePrefix' ) . resolves ( ) ;
1307
1310
@@ -1323,37 +1326,67 @@ describe('AuthInfo', () => {
1323
1326
} ,
1324
1327
} ) ;
1325
1328
1326
- // delete the refresh token
1327
- authInfo . update ( { ...authInfo . getFields ( ) , refreshToken : undefined } ) ;
1328
- expect ( ( ) => authInfo . getSfdxAuthUrl ( ) ) . to . throw ( 'undefined refreshToken' ) ;
1329
+ // delete the client secret
1330
+ authInfo . update ( { clientSecret : undefined } ) ;
1331
+ const instanceUrl = testOrg . instanceUrl . replace ( 'https://' , '' ) ;
1332
+ expect ( authInfo . getSfdxAuthUrl ( ) ) . to . contain ( `force://PlatformCLI::${ testOrg . refreshToken } @${ instanceUrl } ` ) ;
1329
1333
} ) ;
1330
1334
1331
- it ( 'should handle undefined instance url' , async ( ) => {
1332
- stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'determineIfDevHub' ) . resolves ( false ) ;
1333
- stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'getNamespacePrefix' ) . resolves ( ) ;
1335
+ describe ( 'error conditions' , ( ) => {
1336
+ it ( 'should handle undefined refresh token' , async ( ) => {
1337
+ stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'determineIfDevHub' ) . resolves ( false ) ;
1338
+ stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'getNamespacePrefix' ) . resolves ( ) ;
1334
1339
1335
- const authResponse = {
1336
- access_token : testOrg . accessToken ,
1337
- instance_url : testOrg . instanceUrl ,
1338
- id : '00DAuthInfoTest_orgId/005AuthInfoTest_userId' ,
1339
- } ;
1340
+ const authResponse = {
1341
+ access_token : testOrg . accessToken ,
1342
+ instance_url : testOrg . instanceUrl ,
1343
+ id : '00DAuthInfoTest_orgId/005AuthInfoTest_userId' ,
1344
+ } ;
1340
1345
1341
- // Stub the http request (OAuth2.refreshToken())
1342
- postParamsStub . resolves ( authResponse ) ;
1346
+ // Stub the http request (OAuth2.refreshToken())
1347
+ postParamsStub . resolves ( authResponse ) ;
1343
1348
1344
- // Create the refresh token AuthInfo instance
1345
- const authInfo = await AuthInfo . create ( {
1346
- username : testOrg . username ,
1347
- oauth2Options : {
1348
- refreshToken : testOrg . refreshToken ,
1349
- loginUrl : testOrg . loginUrl ,
1350
- } ,
1349
+ // Create the refresh token AuthInfo instance
1350
+ const authInfo = await AuthInfo . create ( {
1351
+ username : testOrg . username ,
1352
+ oauth2Options : {
1353
+ refreshToken : testOrg . refreshToken ,
1354
+ loginUrl : testOrg . loginUrl ,
1355
+ } ,
1356
+ } ) ;
1357
+
1358
+ // delete the refresh token
1359
+ authInfo . update ( { ...authInfo . getFields ( ) , refreshToken : undefined } ) ;
1360
+ expect ( ( ) => authInfo . getSfdxAuthUrl ( ) ) . to . throw ( 'undefined refreshToken' ) ;
1351
1361
} ) ;
1352
1362
1353
- // delete the instance url
1354
- authInfo . update ( { ...authInfo . getFields ( ) , instanceUrl : undefined } ) ;
1363
+ it ( 'should handle undefined instance url' , async ( ) => {
1364
+ stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'determineIfDevHub' ) . resolves ( false ) ;
1365
+ stubMethod ( $$ . SANDBOX , AuthInfo . prototype , 'getNamespacePrefix' ) . resolves ( ) ;
1355
1366
1356
- expect ( ( ) => authInfo . getSfdxAuthUrl ( ) ) . to . throw ( 'undefined instanceUrl' ) ;
1367
+ const authResponse = {
1368
+ access_token : testOrg . accessToken ,
1369
+ instance_url : testOrg . instanceUrl ,
1370
+ id : '00DAuthInfoTest_orgId/005AuthInfoTest_userId' ,
1371
+ } ;
1372
+
1373
+ // Stub the http request (OAuth2.refreshToken())
1374
+ postParamsStub . resolves ( authResponse ) ;
1375
+
1376
+ // Create the refresh token AuthInfo instance
1377
+ const authInfo = await AuthInfo . create ( {
1378
+ username : testOrg . username ,
1379
+ oauth2Options : {
1380
+ refreshToken : testOrg . refreshToken ,
1381
+ loginUrl : testOrg . loginUrl ,
1382
+ } ,
1383
+ } ) ;
1384
+
1385
+ // delete the instance url
1386
+ authInfo . update ( { ...authInfo . getFields ( ) , instanceUrl : undefined } ) ;
1387
+
1388
+ expect ( ( ) => authInfo . getSfdxAuthUrl ( ) ) . to . throw ( 'undefined instanceUrl' ) ;
1389
+ } ) ;
1357
1390
} ) ;
1358
1391
} ) ;
1359
1392
@@ -1703,6 +1736,19 @@ describe('AuthInfo', () => {
1703
1736
expect ( options . loginUrl ) . to . equal ( 'https://test.my.salesforce.com' ) ;
1704
1737
} ) ;
1705
1738
1739
+ it ( 'should parse the correct url with a port on the end' , ( ) => {
1740
+ const options = AuthInfo . parseSfdxAuthUrl (
1741
+ 'force://PlatformCLI::5Aep861_OKMvio5gy8xCNsXxybPdupY9fVEZyeVOvb4kpOZx5Z1QLB7k7n5flEqEWKcwUQEX1I.O5DCFwjlYUB.@test.my.salesforce.com:6101'
1742
+ ) ;
1743
+
1744
+ expect ( options . refreshToken ) . to . equal (
1745
+ '5Aep861_OKMvio5gy8xCNsXxybPdupY9fVEZyeVOvb4kpOZx5Z1QLB7k7n5flEqEWKcwUQEX1I.O5DCFwjlYUB.'
1746
+ ) ;
1747
+ expect ( options . clientId ) . to . equal ( 'PlatformCLI' ) ;
1748
+ expect ( options . clientSecret ) . to . equal ( '' ) ;
1749
+ expect ( options . loginUrl ) . to . equal ( 'https://test.my.salesforce.com:6101' ) ;
1750
+ } ) ;
1751
+
1706
1752
it ( 'should parse an id, secret, and token that include = for padding' , ( ) => {
1707
1753
const options = AuthInfo . parseSfdxAuthUrl (
1708
1754
'force://3MVG9SemV5D80oBfPBCgboxuJ9cOMLWNM1DDOZ8zgvJGsz13H3J66coUBCFF3N0zEgLYijlkqeWk4ot_Q2.4o=:438437816653243682==:5Aep861_OKMvio5gy8xCNsXxybPdupY9fVEZyeVOvb4kpOZx5Z1QLB7k7n5flEqEWKcwUQEX1I.O5DCFwjlYU==@test.my.salesforce.com'
@@ -1718,6 +1764,21 @@ describe('AuthInfo', () => {
1718
1764
expect ( options . loginUrl ) . to . equal ( 'https://test.my.salesforce.com' ) ;
1719
1765
} ) ;
1720
1766
1767
+ it ( 'should parse an id, secret, and token that include = for padding and a port' , ( ) => {
1768
+ const options = AuthInfo . parseSfdxAuthUrl (
1769
+ 'force://3MVG9SemV5D80oBfPBCgboxuJ9cOMLWNM1DDOZ8zgvJGsz13H3J66coUBCFF3N0zEgLYijlkqeWk4ot_Q2.4o=:438437816653243682==:5Aep861_OKMvio5gy8xCNsXxybPdupY9fVEZyeVOvb4kpOZx5Z1QLB7k7n5flEqEWKcwUQEX1I.O5DCFwjlYU==@test.my.salesforce.com:6101'
1770
+ ) ;
1771
+
1772
+ expect ( options . refreshToken ) . to . equal (
1773
+ '5Aep861_OKMvio5gy8xCNsXxybPdupY9fVEZyeVOvb4kpOZx5Z1QLB7k7n5flEqEWKcwUQEX1I.O5DCFwjlYU=='
1774
+ ) ;
1775
+ expect ( options . clientId ) . to . equal (
1776
+ '3MVG9SemV5D80oBfPBCgboxuJ9cOMLWNM1DDOZ8zgvJGsz13H3J66coUBCFF3N0zEgLYijlkqeWk4ot_Q2.4o='
1777
+ ) ;
1778
+ expect ( options . clientSecret ) . to . equal ( '438437816653243682==' ) ;
1779
+ expect ( options . loginUrl ) . to . equal ( 'https://test.my.salesforce.com:6101' ) ;
1780
+ } ) ;
1781
+
1721
1782
it ( 'should parse the correct url with client secret' , ( ) => {
1722
1783
const options = AuthInfo . parseSfdxAuthUrl (
1723
1784
'force://3MVG9SemV5D80oBfPBCgboxuJ9cOMLWNM1DDOZ8zgvJGsz13H3J66coUBCFF3N0zEgLYijlkqeWk4ot_Q2.4o:438437816653243682:5Aep861_OKMvio5gy8xCNsXxybPdupY9fVEZyeVOvb4kpOZx5Z1QLB7k7n5flEqEWKcwUQEX1I.O5DCFwjlYUB.@test.my.salesforce.com'
0 commit comments