Skip to content

Commit

Permalink
Fix failing cli tests (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiaslohr authored Jan 31, 2023
1 parent 40376ff commit c038444
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
10 changes: 5 additions & 5 deletions bin/test-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ else
exit 1
fi

# we have to re-authenticate with API key and user first
echo "Running ´sfcc-ci client:auth <api_key> <secret> <user> <pwd>´:"
node ./cli.js client:auth "$ARG_CLIENT_ID" "$ARG_CLIENT_SECRET" "$ARG_USER" "$ARG_USER_PW"
# Acquire new access token beforehand
echo "Acquire new access token using ´sfcc-ci client:auth <api_key>´:"
node ./cli.js client:auth "$ARG_CLIENT_ID" "$ARG_CLIENT_SECRET"
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
Expand All @@ -215,7 +215,7 @@ else
fi

echo "Testing command ´sfcc-ci client:create --configuration <configuration>´ --noprompt:"
TEST_NEW_CLIENT_RESULT=`node ./cli.js client:create --configuration '{"name": "My new client", "password": "%2secret(Sauce7?!"}' --json`
TEST_NEW_CLIENT_RESULT=`node ./cli.js client:create --configuration '{"name": "Temp test client", "password": "%2secret(Sauce7?!"}' --noprompt --json`
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
Expand Down Expand Up @@ -292,7 +292,7 @@ else
fi

echo "Testing command ´sfcc-ci client:rotate --clientid <client_id> --noprompt´:"
TEST_ROTATION_RESULT=`node ./cli.js client:rotate --clientid $TEST_NEW_CLIENT_ID --noprompt`
TEST_ROTATION_RESULT=`node ./cli.js client:rotate --clientid $TEST_NEW_CLIENT_ID --noprompt --json`
if [ $? -eq 0 ]; then
echo -e "\t> OK"
else
Expand Down
4 changes: 4 additions & 0 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,8 +624,10 @@ async function getAuthenticatedUser() {
request(options, function (err, res, body) {
if ( err ) {
reject(new Error(`Lookup of authenticated user failed: ${err}`));
return;
} else if ( res.statusCode >= 400 ) {
reject(new Error(`Lookup of authenticated user failed: ${res.statusCode}`));
return;
}
resolve(body);
});
Expand Down Expand Up @@ -665,8 +667,10 @@ async function getAuthenticatedClient() {
}, function (err, res, body) {
if ( err ) {
reject(new Error(`Lookup of authenticated client failed: ${err}`));
return;
} else if ( res.statusCode >= 400 ) {
reject(new Error(`Lookup of authenticated client failed: ${res.statusCode}`));
return;
}
resolve(body);
});
Expand Down
13 changes: 11 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ async function getClient(id) {
var error = captureCommonErrors(err, res);
if ( res.statusCode === 404 ) {
reject(new Error(`Oauth client not found`));
return;
} else if ( error ) {
reject(error)
reject(error);
return;
}
resolve(toExternal(body));
});
Expand All @@ -112,8 +114,10 @@ async function listClients(page, size) {
var error = captureCommonErrors(err, res);
if ( res.statusCode === 404 ) {
reject(new Error(`No Oauth clients found`));
return;
} else if ( error ) {
reject(error)
reject(error);
return;
}
resolve(body.content);
});
Expand Down Expand Up @@ -147,6 +151,7 @@ async function updateClient(client, changes) {
var error = captureCommonErrors(err, res);
if ( error ) {
reject(error);
return;
}
resolve(toExternal(body));
});
Expand All @@ -172,6 +177,7 @@ async function createClient(client) {
var error = captureCommonErrors(err, res);
if ( error ) {
reject(error);
return;
}
resolve(toExternal(body));
});
Expand Down Expand Up @@ -249,6 +255,7 @@ async function rotateCredentials(client) {
var error = captureCommonErrors(err, res);
if ( error ) {
reject(error);
return;
}
resolve([body, newSecret]);
});
Expand All @@ -271,6 +278,7 @@ async function deleteClient(client) {
var error = captureCommonErrors(err, res);
if ( error ) {
reject(error);
return;
}
resolve();
});
Expand Down Expand Up @@ -325,6 +333,7 @@ module.exports.cli = {
// finally check, if we have an org
if (!clientDefinition.organizations || clientDefinition.organizations.length == 0) {
reject(new Error(`No organization specified`));
return;
}
resolve(clientDefinition);
})).then(clientDefinition => {
Expand Down
1 change: 1 addition & 0 deletions lib/org.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ async function getOrgById(orgId) {
var error = captureCommonErrors(err, res);
if ( error ) {
reject(error);
return;
}
resolve(body);
});
Expand Down

0 comments on commit c038444

Please sign in to comment.