11.7. 测试配置的 API
您可以通过在向应用程序发出调用时执行身份验证检查来验证 API 配置的有效性。通过全面测试身份验证机制,您可以确保只处理授权请求、维护应用程序的安全性和完整性。
流程
尝试使用
WasmPlugin
应用调用 Bookinfo 应用程序。它应该被拒绝,因为我们没有包含任何身份验证:export GATEWAY_URL=$(oc -n istio-system get route istio-ingressgateway -o jsonpath='{.spec.host}') curl -I "http://$GATEWAY_URL/productpage"
$ export GATEWAY_URL=$(oc -n istio-system get route istio-ingressgateway -o jsonpath='{.spec.host}') $ curl -I "http://$GATEWAY_URL/productpage" HTTP/1.1 403
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 检索用于身份验证的用户密钥:
- 进入 [Your_product_name] > Applications > Listings。
- 选项您的应用程序
- 查找 Authentication > User Key。
使用显示的用户密钥尝试再次进行调用。
curl -I "http://$GATEWAY_URL/productpage?user_key=$USER_KEY"
$ curl -I "http://$GATEWAY_URL/productpage?user_key=$USER_KEY" HTTP/1.1 200 OK
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 验证在指标中注册了 hit。
- 进入 [Your_product_name] > Analytics > Traffic。
- 您应看到注册了您的调用。