diff --git a/.github/workflows/bats-test.yml b/.github/workflows/bats-test.yml index d49baea..4762070 100644 --- a/.github/workflows/bats-test.yml +++ b/.github/workflows/bats-test.yml @@ -10,15 +10,62 @@ on: - test/test.bats.sh jobs: - test: - runs-on: ubuntu-18.04 # Test on old version bash + test-on-alpine: + runs-on: ubuntu-latest + container: + image: alpine:latest steps: - - name: Check out code - uses: actions/checkout@v3 + - name: Check out code + uses: actions/checkout@v3 with: submodules: true - - name: Run test - env: - AliAccessKeyId: ${{ secrets.ALIACCESSKEYID }} - AliAccessKeySecret: ${{ secrets.ALIACCESSKEYSECRET }} + - name: Install dependencies + run: apk add bash curl openssl + - name: Run test + env: + AliAccessKeyId: ${{ secrets.ALIACCESSKEYID }} + AliAccessKeySecret: ${{ secrets.ALIACCESSKEYSECRET }} + run: ./test/bats/bin/bats test/test.bats.sh + + test-on-openwrt: + runs-on: ubuntu-latest + container: + image: openwrtorg/rootfs:x86-64-openwrt-22.03 + steps: + - name: Fix var directory + run: mkdir -p /var/lock + - name: Install dependencies + run: | + opkg update + opkg install git git-http + opkg install bash curl openssl-util + # Bats dependencies + opkg install coreutils-nl + - name: Check out code + if: ${{ github.event.act }} + uses: actions/checkout@v3 + with: + submodules: true + - name: Check out code (with git) + if: ${{ !github.event.act }} + run: git clone --depth 1 --no-tags --recurse-submodules https://github.com/${{ github.repository }}.git /tmp/${{ github.sha }} + - name: Run test + env: + AliAccessKeyId: ${{ secrets.ALIACCESSKEYID }} + AliAccessKeySecret: ${{ secrets.ALIACCESSKEYSECRET }} + run: | + [[ -d /tmp/${{ github.sha }} ]] && cd /tmp/${{ github.sha }} + ./test/bats/bin/bats test/test.bats.sh + + test-on-ubuntu: + runs-on: ubuntu-18.04 # Test on old version bash + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + submodules: true + - name: Run test + env: + AliAccessKeyId: ${{ secrets.ALIACCESSKEYID }} + AliAccessKeySecret: ${{ secrets.ALIACCESSKEYSECRET }} run: ./test/bats/bin/bats test/test.bats.sh diff --git a/.gitignore b/.gitignore index 9772ff8..ddc7fc5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .env.dev .env.local .env.test +.secrets diff --git a/AliyunOpenApiSDK.sh b/AliyunOpenApiSDK.sh index a2e488e..31bf6e9 100755 --- a/AliyunOpenApiSDK.sh +++ b/AliyunOpenApiSDK.sh @@ -8,6 +8,8 @@ for _aliapi_command in openssl curl; do done unset _aliapi_command +_ALIYUN_SDK_RUN_ON_MUSL_LIBC=$(ldd "$SHELL" | grep -q /lib/ld-musl && echo 1 || echo 0) + ALIYUN_SDK_LAST_HTTP_CODE=0 # aliapi_rpc [<--key> ...] @@ -73,12 +75,17 @@ _aliapi_check_vars() { } _aliapi_signature_rpc() { + if [[ ${LC_ALL:-X} != C ]]; then + LC_ALL=C _aliapi_signature_rpc "$@" + return $? + fi + local -u _http_method=$1 local _str=$2 _query_str _sign_str local _newline=' ' - _str=$(LC_ALL=C sort <<< "${_str//&/$_newline}") - _query_str=${_str//$_newline/&} + _str=$(sort <<< "${_str//"&"/"$_newline"}") + _query_str=${_str//"$_newline"/"&"} _sign_str="$_http_method&$(_aliapi_urlencode "/")&$(_aliapi_urlencode "$_query_str")" printf "%s" "$_sign_str" | openssl dgst -sha1 -hmac "$_AliAccessKeySecret&" -binary | openssl base64 -e } @@ -103,13 +110,21 @@ _aliapi_urlencode() { LC_ALL=C _aliapi_urlencode "$@" return $? fi - local char string=$1 + local char hex string=$1 while [[ -n $string ]]; do char=${string:0:1} string=${string:1} case $char in [-._~0-9A-Za-z]) printf %c "$char";; - *) printf %%%02X "'$char";; + *) + if [[ _ALIYUN_SDK_RUN_ON_MUSL_LIBC -eq 1 ]]; then + # Hack musl libc for not ASCII chars (incomplete test) + hex=$(printf %02X "'$char") + printf %%%s "${hex:${#hex}-2}" + else + printf %%%02X "'$char" + fi + ;; esac done echo