Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests --key-file flag and GOOGLE_APPLICATION_CREDENTIALS env with admin permission tests #1167

Merged
merged 124 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
33ff441
updating go version
Tulsishah May 24, 2023
1e4759f
empty commit
Tulsishah May 24, 2023
3c5a7cb
Merge branch 'GoogleCloudPlatform:master' into master
Tulsishah May 26, 2023
2961ae7
local commit
Tulsishah May 30, 2023
c714410
local changes
Tulsishah May 30, 2023
8f23bc6
local changes
Tulsishah May 31, 2023
4d51222
local changes
Tulsishah May 31, 2023
e00b8e4
adding key file tests
Tulsishah Jun 1, 2023
adaa358
testing
Tulsishah Jun 1, 2023
942d972
testing
Tulsishah Jun 1, 2023
0f891ae
testing
Tulsishah Jun 1, 2023
dc7589b
testing
Tulsishah Jun 1, 2023
230c85a
local changes
Tulsishah Jun 5, 2023
e66dd82
local changes
Tulsishah Jun 5, 2023
d9d5786
local changes
Tulsishah Jun 5, 2023
eed5e4f
local changes
Tulsishah Jun 5, 2023
8c6edc8
testing
Tulsishah Jun 6, 2023
78ec30d
testing
Tulsishah Jun 6, 2023
f5be292
testing
Tulsishah Jun 6, 2023
075da7f
testing
Tulsishah Jun 6, 2023
3825034
Merge branch 'GoogleCloudPlatform:master' into key_file_view_tests
Tulsishah Jun 6, 2023
f483f6c
testing
Tulsishah Jun 6, 2023
60429b4
testing
Tulsishah Jun 6, 2023
e3538b0
adding test for admin creds
Tulsishah Jun 6, 2023
27bdcd5
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jun 6, 2023
35a7a59
testing
Tulsishah Jun 6, 2023
feda295
testing
Tulsishah Jun 6, 2023
bd5cfc9
testing
Tulsishah Jun 6, 2023
fc385d2
testing
Tulsishah Jun 6, 2023
ec76c5e
testing
Tulsishah Jun 6, 2023
e877b3b
testing
Tulsishah Jun 6, 2023
24e45b0
testing
Tulsishah Jun 6, 2023
26578e7
testing
Tulsishah Jun 6, 2023
0675c1c
testing
Tulsishah Jun 6, 2023
5e80475
testing
Tulsishah Jun 6, 2023
944d3f8
testing
Tulsishah Jun 6, 2023
a3a193b
testing
Tulsishah Jun 6, 2023
58481c1
formating
Tulsishah Jun 6, 2023
2fc526d
testing defer statement
Tulsishah Jun 6, 2023
eba2c07
testing defer statement for deleting credentials
Tulsishah Jun 6, 2023
604bd9c
adding comment
Tulsishah Jun 6, 2023
59b3fcd
testing with error
Tulsishah Jun 6, 2023
b74889b
testing with error
Tulsishah Jun 6, 2023
5308c6d
testing with error
Tulsishah Jun 6, 2023
aa9ef8c
removing testing statement
Tulsishah Jun 6, 2023
1ca5064
adding testbucket and mntdir in commnd
Tulsishah Jun 7, 2023
6e9776f
adding comment
Tulsishah Jun 7, 2023
dd57856
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jun 8, 2023
5125001
updating bucket name
Tulsishah Jun 12, 2023
2e5b0e6
updating bucket name
Tulsishah Jun 12, 2023
ec267fe
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jun 12, 2023
d06b9ff
merging
Tulsishah Jun 12, 2023
f7b5a8b
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_test
Tulsishah Jun 27, 2023
5cb9d14
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jun 27, 2023
90cd9aa
resolving merge conflict
Tulsishah Jun 27, 2023
09f29cc
resolving merge conflict
Tulsishah Jun 27, 2023
c40d402
removing unnecessary changes
Tulsishah Jun 27, 2023
fcabc6f
removing unnecessary changes
Tulsishah Jun 27, 2023
b41927e
removing unnecessary changes
Tulsishah Jun 27, 2023
93423d7
formatting
Tulsishah Jun 27, 2023
600e58a
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jun 27, 2023
4200e1a
conflict
Tulsishah Jun 27, 2023
e38c9d2
adding error handling
Tulsishah Jun 27, 2023
1e063ad
testing
Tulsishah Jun 27, 2023
0b9dd11
small fix
Tulsishah Jun 27, 2023
b8cb0f0
removing creds tests from implicit and explicit dir tests
Tulsishah Jun 27, 2023
7e29812
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jun 28, 2023
97550aa
testing
Tulsishah Jun 29, 2023
f23f9b6
testing
Tulsishah Jun 29, 2023
806743b
testing
Tulsishah Jun 29, 2023
10eed59
testing
Tulsishah Jun 29, 2023
0e648d7
removing testing statement
Tulsishah Jun 29, 2023
f549903
adding creds tests in operations back
Tulsishah Jun 29, 2023
25013fe
Testing
Tulsishah Jul 1, 2023
5c6dda1
Testing
Tulsishah Jul 1, 2023
7c462df
Testing
Tulsishah Jul 1, 2023
a4dfc31
create service account key testing
Tulsishah Jul 1, 2023
0ba2c3b
create service account key testing
Tulsishah Jul 1, 2023
54b3fae
create service account key testing
Tulsishah Jul 1, 2023
4a6dedc
create service account key testing
Tulsishah Jul 1, 2023
83028e4
create service account key testing
Tulsishah Jul 1, 2023
a007a12
create service account key testing
Tulsishah Jul 1, 2023
c285e5c
create service account key testing
Tulsishah Jul 1, 2023
5803656
create service account key testing
Tulsishah Jul 1, 2023
de87eed
create service account key testing
Tulsishah Jul 1, 2023
f3aac0e
create service account key testing
Tulsishah Jul 1, 2023
d5518e4
create service account key testing
Tulsishah Jul 1, 2023
6d98b5f
create service account key testing
Tulsishah Jul 1, 2023
df3f911
create service account key testing
Tulsishah Jul 1, 2023
c44f1c7
create service account key testing
Tulsishah Jul 1, 2023
98da29c
create service account key testing
Tulsishah Jul 1, 2023
c5735ba
create service account key testing
Tulsishah Jul 1, 2023
5f5f78a
adding remaining changes
Tulsishah Jul 1, 2023
a44986e
adding remaining changes
Tulsishah Jul 1, 2023
ff39046
adding remaining changes
Tulsishah Jul 1, 2023
181cf54
testing service account
Tulsishah Jul 4, 2023
48f32c6
testing service account
Tulsishah Jul 4, 2023
49ad5f2
testing service account
Tulsishah Jul 4, 2023
ac682ad
adding comments
Tulsishah Jul 4, 2023
b825e1f
removing unnecessary changes
Tulsishah Jul 4, 2023
bc9e6e5
formatting
Tulsishah Jul 4, 2023
c8fb801
testing
Tulsishah Jul 4, 2023
0a19e07
testing
Tulsishah Jul 4, 2023
5a47330
testing
Tulsishah Jul 4, 2023
9cac5cd
testing
Tulsishah Jul 4, 2023
c50d04c
removing without key file tests
Tulsishah Jul 10, 2023
02b78c2
small fix
Tulsishah Jul 10, 2023
2614040
Merge branch 'GoogleCloudPlatform:master' into key_file_admin_tests
Tulsishah Jul 10, 2023
db87848
formalizing for reuse
Tulsishah Jul 10, 2023
a496a2d
merrging
Tulsishah Jul 10, 2023
47f66a0
small fix
Tulsishah Jul 10, 2023
4c55e74
removing unnecessary changes
Tulsishah Jul 10, 2023
b753e4f
formatting
Tulsishah Jul 10, 2023
9f9e55e
updating comment
Tulsishah Jul 10, 2023
cbd3487
updating comment
Tulsishah Jul 10, 2023
260b90c
updating comment
Tulsishah Jul 10, 2023
ff31eb3
fixing comments
Tulsishah Jul 11, 2023
38032b1
adding comment
Tulsishah Jul 11, 2023
9525a20
testing
Tulsishah Jul 11, 2023
9b02af7
testing
Tulsishah Jul 11, 2023
4e836be
adding condintion for service account already exsit
Tulsishah Jul 11, 2023
30a9631
adding condintion for service account already exsit
Tulsishah Jul 11, 2023
19f06bf
testing time
Tulsishah Jul 11, 2023
ca6ce06
running tests only for operations
Tulsishah Jul 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/creds_tests"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
Expand Down Expand Up @@ -107,5 +108,10 @@ func TestMain(m *testing.M) {
successCode = only_dir_mounting.RunTests(flags, m)
}

if successCode == 0 {
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
// Test for admin permission on test bucket.
successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m)
}

os.Exit(successCode)
}
104 changes: 104 additions & 0 deletions tools/integration_tests/util/creds_tests/creds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2023 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// 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.

// Run tests for --key-file flag and GOOGLE_APPLICATION_CREDENTIALS env variable

package creds_tests

import (
"fmt"
"log"
"os"
"path"
"testing"

"cloud.google.com/go/compute/metadata"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

const NameOfServiceAccount = "creds-test-gcsfuse"

func setPermission(permission string, serviceAccount string) {
// Provide permission to the bucket.
setup.RunScriptForTestData("../util/creds_tests/testdata/provide_permission.sh", setup.TestBucket(), serviceAccount, permission)
}

func RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(testFlagSet [][]string, permission string, m *testing.M) (successCode int) {
// Fetching project-id to get service account id.
id, err := metadata.ProjectID()
if err != nil {
log.Printf("Error in fetching project id: %v", err)
}

// Service account id format is name@project-id.iam.gserviceaccount.com
serviceAccount := NameOfServiceAccount + "@" + id + ".iam.gserviceaccount.com"

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

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

// Create credentials
setup.RunScriptForTestData("../util/creds_tests/testdata/create_key_file.sh", key_file_path, serviceAccount)

// 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)

// 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.
// https://github.com/golang/oauth2/blob/master/google/default.go#L160

// Testing with GOOGLE_APPLICATION_CREDENTIALS env variable
err = os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", key_file_path)
if err != nil {
setup.LogAndExit(fmt.Sprintf("Error in setting environment variable: %v", err))
}

successCode = static_mounting.RunTests(testFlagSet, m)

if successCode != 0 {
return
}

// Testing with --key-file and GOOGLE_APPLICATION_CREDENTIALS env variable set
keyFileFlag := "--key-file=" + key_file_path

for i := 0; i < len(testFlagSet); i++ {
testFlagSet[i] = append(testFlagSet[i], keyFileFlag)
}

successCode = static_mounting.RunTests(testFlagSet, m)

if successCode != 0 {
return
}

err = os.Unsetenv("GOOGLE_APPLICATION_CREDENTIALS")
if err != nil {
setup.LogAndExit(fmt.Sprintf("Error in unsetting environment variable: %v", err))
}

// Testing with --key-file flag only
successCode = static_mounting.RunTests(testFlagSet, m)

if successCode != 0 {
return
}

return successCode
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

KEY_FILE_PATH=$1
SERVICE_ACCOUNT=$2
gcloud iam service-accounts keys create $KEY_FILE_PATH --iam-account=$SERVICE_ACCOUNT
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

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."
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
@@ -0,0 +1,20 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

# Provide permission to the bucket.
TEST_BUCKET=$1
SERVICE_ACCOUNT=$2
PERMISSION=$3

gsutil iam ch serviceAccount:$SERVICE_ACCOUNT:$PERMISSION gs://$TEST_BUCKET
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

# Delete service account after testing
SERVICE_ACCOUNT=$1
KEY_FILE=$2
gcloud auth revoke $SERVICE_ACCOUNT
gcloud iam service-accounts delete $SERVICE_ACCOUNT
rm $KEY_FILE