Cors 테스트 방법
먼저 cURL을 다운 받는다.
터미널에 아래 명령어를 입력한다.
- 아래 명령어 중 괄호 안에 있는 부분을 내 테스트에 맞게 변경한다.
- request 포트번호는 8080말고 5050 등 다른 걸로 하면 된다.
// 요청하는 cURL 명령
curl \
--verbose \
--request OPTIONS \
https://hyunjun.herokuapp.com/user-id-validation (Cors 확인하고 싶은 api 주소) \
--header 'Origin: http://localhost:8080'(request 하는 포트 번호) \
--header 'Access-Control-Request-Headers: Origin, Accept, Content-Type' \
--header 'Access-Control-Request-Method: POST'
--header 'api-key: test-vas'
테스트 결과
- 성공하면 응답 결과로 < HTTP/1.1 200 가 뜬다.
- 실패하면 응답 결과로 403 등이 뜬다.
// 성공시 나오는 response
* Trying 52.71.209.91...
* TCP_NODELAY set
* Connected to hyunjun.herokuapp.com (52.71.209.91) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Heroku, Inc.; CN=*.herokuapp.com
* start date: Apr 19 00:00:00 2017 GMT
* expire date: Jun 22 12:00:00 2020 GMT
* subjectAltName: host "hyunjun.herokuapp.com" matched cert's "*.herokuapp.com"
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
> OPTIONS /user-id-validation HTTP/1.1
> Host: hyunjun.herokuapp.com
> User-Agent: curl/7.58.0
> Accept: */*
> Origin: http://localhost:5050
> Access-Control-Request-Headers: Origin, Accept, Content-Type
> Access-Control-Request-Method: POST
>
< HTTP/1.1 200
< Server: Cowboy
< Connection: keep-alive
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET,HEAD,POST
< Access-Control-Allow-Headers: Origin, Accept, Content-Type
< Access-Control-Max-Age: 1800
< Allow: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
< Content-Length: 0
< Date: Thu, 26 Mar 2020 08:46:30 GMT
< Via: 1.1 vegur
<