This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathe2etest.sh
executable file
·86 lines (73 loc) · 2.91 KB
/
e2etest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# Copyright 2019 Google LLC
#
# 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
#
# https://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.
# Minimum end-to-end test
#
# Usage: ./e2etest.sh USER_EMAIL SERVICE_ACCOUNT_EMAIL
#
# USER_EMAIL should be an account registered in gcloud. SERVICE_ACCOUNT_EMAIL
# should be a service account that is accessible from the application default
# credential.
tmpdir=$(mktemp -d)
atexit() {
rm -rf $tmpdir
}
trap atexit EXIT
gcloud_user=$1
service_account_user=$2
cd /
export GIT_CONFIG_NOSYSTEM=1
export GIT_TERMINAL_PROMPT=0
orig_home=$HOME
export HOME=$tmpdir
touch $HOME/.gitconfig
ln -s $orig_home/.config $HOME/.config
# ------------------------------------------------------------------------------
# Auth config tests
# ------------------------------------------------------------------------------
# google.account = <GOOGLE_ACCOUNT>
cat >$HOME/.gitconfig <<EOF
[google]
account = $gcloud_user
EOF
googlesource-cookieauth -c google.cookieFile=$HOME/.gitcookies || exit 1
git -c http.cookieFile=$HOME/.gitcookies ls-remote https://code.googlesource.com/a/git >/dev/null || exit 1
# google.account = application-default
cat >$HOME/.gitconfig <<EOF
[google]
account = application-default
EOF
googlesource-cookieauth -c google.cookieFile=$HOME/.gitcookies || exit 1
git -c http.cookieFile=$HOME/.gitcookies ls-remote https://code.googlesource.com/a/git >/dev/null || exit 1
# google.account = <SERVICE_ACCOUNT>
cat >$HOME/.gitconfig <<EOF
[google]
account = $service_account_user
EOF
googlesource-cookieauth -c google.cookieFile=$HOME/.gitcookies || exit 1
git -c http.cookieFile=$HOME/.gitcookies ls-remote https://code.googlesource.com/a/git >/dev/null || exit 1
# ------------------------------------------------------------------------------
# Auth helper tests
# ------------------------------------------------------------------------------
# Sanity check. /a/ URLs cannot be accessed without a credential.
if git ls-remote https://code.googlesource.com/a/git >/dev/null 2>/dev/null; then
exit 1
fi
# git-credential-googlesource
git -c credential.helper=googlesource ls-remote https://code.googlesource.com/a/git >/dev/null || exit 1
# googlesource-askpass
GIT_ASKPASS=googlesource-askpass git ls-remote https://code.googlesource.com/a/git >/dev/null || exit 1
# googlesource-cookieauth
googlesource-cookieauth -c google.cookieFile=$HOME/.gitcookies || exit 1
git -c http.cookieFile=$HOME/.gitcookies ls-remote https://code.googlesource.com/a/git >/dev/null || exit 1