Skip to content

Commit

Permalink
Creds test error fixing Integration tests (#1241)
Browse files Browse the repository at this point in the history
* testing

* testing

* testing

* testing

* creating service account if does not exist

* removing unnecessary params

* formatting

* formatting

* adding relavant comments

* updating path

* fixing comment

* adding command for removing file

* small fix in script to update path of file
  • Loading branch information
Tulsishah authored Jul 25, 2023
1 parent 74aa5f2 commit eb86cd1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
6 changes: 3 additions & 3 deletions tools/integration_tests/util/creds_tests/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(testFlagSet [][]
serviceAccount := NameOfServiceAccount + "@" + id + ".iam.gserviceaccount.com"

// Create service account
setup.RunScriptForTestData("../util/creds_tests/testdata/create_service_account.sh", NameOfServiceAccount, serviceAccount)
setup.RunScriptForTestData("../util/creds_tests/testdata/create_service_account.sh", NameOfServiceAccount)

key_file_path := path.Join(os.Getenv("HOME"), "creds.json")

Expand All @@ -56,8 +56,8 @@ func RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(testFlagSet [][]
// Provide permission to service account for testing.
setPermission(permission, serviceAccount)

// Revoke the permission and delete creds and service account after testing.
defer setup.RunScriptForTestData("../util/creds_tests/testdata/revoke_permission_and_delete_service_account_and_creds.sh", serviceAccount, key_file_path)
// Revoke the permission and delete creds after testing.
defer setup.RunScriptForTestData("../util/creds_tests/testdata/revoke_permission_and_creds.sh", serviceAccount, key_file_path)

// Without –key-file flag and GOOGLE_APPLICATION_CREDENTIALS
// This case will not get covered as gcsfuse internally authenticates from a metadata server on GCE VM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@

KEY_FILE_PATH=$1
SERVICE_ACCOUNT=$2
gcloud iam service-accounts keys create $KEY_FILE_PATH --iam-account=$SERVICE_ACCOUNT
gcloud iam service-accounts keys create $KEY_FILE_PATH --iam-account=$SERVICE_ACCOUNT 2>&1 | tee ~/key_id.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Create service account if does not exist.

SERVICE_ACCOUNT=$1
SERVICE_ACCOUNT_ID=$2
# Delete service account if already exist.
gcloud iam service-accounts delete $SERVICE_ACCOUNT_ID
if [ $? -eq 1 ]; then
echo "Service account does not exist."

gcloud iam service-accounts create $SERVICE_ACCOUNT --description="$SERVICE_ACCOUNT" --display-name="$SERVICE_ACCOUNT" 2>&1 | tee ~/output.txt
if grep "already exists within project" ~/output.txt; then
echo "Service account exist."
rm ~/output.txt
else
rm ~/output.txt
exit 1
fi
gcloud iam service-accounts create $SERVICE_ACCOUNT --description="$SERVICE_ACCOUNT" --display-name="$SERVICE_ACCOUNT"
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Delete service account after testing
# Delete key file after testing
SERVICE_ACCOUNT=$1
KEY_FILE=$2

gcloud auth revoke $SERVICE_ACCOUNT
gcloud iam service-accounts delete $SERVICE_ACCOUNT
# Crete key file output
# e.g. Created key [KEY_ID] of type [json] as [key_file_path] for [service_account]
# Capturing third word from the file to get key-id
# e.g. Capture [KEY_ID]
if [ ! -f "~/key_id.txt" ]; then
echo "file does not exist"
fi
KEY_ID=$(cat ~/key_id.txt | cut -d " " -f 3)
# removing braces
# e.g. capture KEY_ID
KEY_ID=${KEY_ID:1:40}

gcloud iam service-accounts keys delete $KEY_ID --iam-account=$SERVICE_ACCOUNT
rm ~/key_id.txt
rm $KEY_FILE

0 comments on commit eb86cd1

Please sign in to comment.