| #!/usr/bin/env bash |
| |
| readlink -f / &> /dev/null || readlink() { greadlink "$@" ; } # for MacOS |
| MYDIR=$(dirname -- "$(readlink -f -- "$0")") |
| |
| source "$MYDIR/lib_helpers.sh" |
| source "$MYDIR/lib_result.sh" |
| |
| HTTP_PORT=8080 |
| REMOTE_GERRIT_BASE_URL="http://$REMOTE_GERRIT_HOST:$HTTP_PORT" |
| GERRIT_BASE_URL="http://$GERRIT_HOST:$HTTP_PORT" |
| |
| q gcurl --header "Content-Type: application/json" \ |
| --request PUT "$REMOTE_GERRIT_BASE_URL/a/accounts/user1" \ |
| --data @<(cat <<EOF |
| { |
| "email": "user1@example.com" |
| } |
| EOF |
| ) |
| q gcurl --request PUT "$GERRIT_BASE_URL/a/accounts/user1" |
| ACTUAL=$(gcurl --request GET "$GERRIT_BASE_URL/a/accounts/user1") |
| EXPECTED=$(cat <<EOF |
| { |
| "_account_id": 1000001, |
| "email": "user1@example.com", |
| "name": "user1", |
| "username": "user1" |
| } |
| EOF |
| ) |
| result_out_json "Email added on remote gerrit site is available on the internal site" \ |
| "$EXPECTED" "$ACTUAL" |
| |
| # The test case assumes that `user1` does not have `user1@secondary.com` email |
| # address configured on remote gerrit site and internal site has the external |
| # id configured in $GERRIT_SITE/etc/remote-gerrit-account-cache_externalIds |
| ACTUAL=$(gcurl --request GET "$GERRIT_BASE_URL/a/accounts/user1/external.ids" | \ |
| jq '.[] | select(.identity == "mailto:user1@secondary.com")') |
| EXPECTED=$(cat <<EOF |
| { |
| "can_delete": true, |
| "email_address": "user1@secondary.com", |
| "identity": "mailto:user1@secondary.com", |
| "trusted": true |
| } |
| EOF |
| ) |
| result_out_json "Configured external id is available on the internal site" \ |
| "$EXPECTED" "$ACTUAL" |
| |
| exit "$RESULT" |