#!/usr/bin/env bash # The root of the build/dist directory IAM_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. [[ -z ${COMMON_SOURCED} ]] && source ${IAM_ROOT}/scripts/install/common.sh # API Server API Address:Port INSECURE_OPENIMAPI=${IAM_APISERVER_HOST}:${API_OPENIM_PORT} INSECURE_OPENIMAUTO=${OPENIM_RPC_AUTH_HOST}:${OPENIM_AUTH_PORT} CCURL="curl -f -s -XPOST" # Create UCURL="curl -f -s -XPUT" # Update RCURL="curl -f -s -XGET" # Retrieve DCURL="curl -f -s -XDELETE" # Delete openim::test::check_error() { local response=$1 local err_code=$(echo "$response" | jq '.errCode') openim::log::status "Response from user registration: $response" if [[ "$err_code" != "0" ]]; then openim::log::error_exit "Error occurred: $response, You can read the error code in the API documentation https://docs.openim.io/restapi/errcode" else openim::log::success "Operation was successful." fi } # The `openim::test::auth` function serves as a test suite for authentication-related operations. function openim::test::auth() { # 1. Retrieve and set the authentication token. openim::test::get_token # 2. Force logout the test user from a specific platform. openim::test::force_logout # Log the completion of the auth test suite. openim::log::success "Auth test suite completed successfully." } #################################### Auth Module #################################### # Define a function to get a token (Admin Token) openim::test::get_token() { token_response=$(${CCURL} "${OperationID}" "${Header}" http://${OPENIM_API_HOST}:${API_OPENIM_PORT}/auth/user_token \ -d'{"secret": "'"$SECRET"'","platformID": 1,"userID": "openIM123456"}') token=$(echo $token_response | grep -Po 'token[" :]+\K[^"]+') echo "$token" } Header="-HContent-Type: application/json" OperationID="-HoperationID: 1646445464564" Token="-Htoken: $(openim::test::get_token)" # Forces a user to log out from the specified platform by user ID. openim::test::force_logout() { local request_body=$(cat <