123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- #
- # Licensed to the Apache Software Foundation (ASF) under one or more
- # contributor license agreements. See the NOTICE file distributed with
- # this work for additional information regarding copyright ownership.
- # The ASF licenses this file to You under the Apache License, Version 2.0
- # (the "License"); you may not use this file except in compliance with
- # the License. You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #
- use t::APISIX;
- repeat_each(1);
- log_level('info');
- no_root_location();
- no_shuffle();
- my $openssl_bin = $ENV{OPENSSL_BIN};
- if (! -x $openssl_bin) {
- $ENV{OPENSSL_BIN} = '/usr/local/openresty/openssl3/bin/openssl';
- if (! -x $ENV{OPENSSL_BIN}) {
- plan(skip_all => "openssl3 not installed");
- }
- }
- plan('no_plan');
- add_block_preprocessor(sub {
- my ($block) = @_;
- my $yaml_config = $block->yaml_config // <<_EOC_;
- deployment:
- role: traditional
- role_traditional:
- config_provider: etcd
- admin:
- admin_key: null
- apisix:
- node_listen: 1984
- proxy_mode: http&stream
- stream_proxy:
- tcp:
- - 9100
- enable_resolv_search_opt: false
- ssl:
- ssl_protocols: TLSv1.1 TLSv1.2 TLSv1.3
- ssl_ciphers: ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA
- _EOC_
- $block->set_value("yaml_config", $yaml_config);
- });
- run_tests();
- __DATA__
- === TEST 1: set route
- --- config
- location /t {
- content_by_lua_block {
- local t = require("lib.test_admin").test
- local code, body = t('/apisix/admin/routes/1',
- ngx.HTTP_PUT,
- [[{
- "upstream": {
- "nodes": {
- "127.0.0.1:1980": 1
- },
- "type": "roundrobin"
- },
- "uris": ["/hello", "/world"]
- }]]
- )
- if code >= 300 then
- ngx.status = code
- ngx.say(message)
- return
- end
- ngx.say(body)
- }
- }
- --- request
- GET /t
- --- response_body
- passed
- === TEST 2: create ssl for test.com (unset ssl_protocols)
- --- config
- location /t {
- content_by_lua_block {
- local core = require("apisix.core")
- local t = require("lib.test_admin")
- local ssl_cert = t.read_file("t/certs/apisix.crt")
- local ssl_key = t.read_file("t/certs/apisix.key")
- local data = {cert = ssl_cert, key = ssl_key, sni = "test.com"}
- local code, body = t.test('/apisix/admin/ssls/1',
- ngx.HTTP_PUT,
- core.json.encode(data),
- [[{
- "value": {
- "sni": "test.com",
- "ssl_protocols": null,
- },
- "key": "/apisix/ssls/1"
- }]]
- )
- ngx.status = code
- ngx.say(body)
- }
- }
- --- request
- GET /t
- --- response_body
- passed
- === TEST 3: Successfully, access test.com with TLSv1.3
- --- exec
- echo -n "Q" | $OPENSSL_BIN s_client -connect 127.0.0.1:1994 -servername test.com -tls1_3 2>&1 | cat
- --- response_body eval
- qr/Server certificate/
- === TEST 4: Successfully, access test.com with TLSv1.2
- --- exec
- curl -k -v --tls-max 1.2 --tlsv1.2 --resolve "test.com:1994:127.0.0.1" https://test.com:1994/hello 2>&1 | cat
- --- response_body eval
- qr/TLSv1\.2 \(IN\), TLS handshake, Server hello(?s).*hello world/
- === TEST 5: Successfully, access test.com with TLSv1.1
- --- exec
- echo -n "Q" | $OPENSSL_BIN s_client -connect 127.0.0.1:1994 -servername test.com -tls1_1 2>&1 | cat
- --- response_body eval
- qr/Server certificate/
- === TEST 6: set TLSv1.2 and TLSv1.3 for test.com
- --- config
- location /t {
- content_by_lua_block {
- local core = require("apisix.core")
- local t = require("lib.test_admin")
- local ssl_cert = t.read_file("t/certs/apisix.crt")
- local ssl_key = t.read_file("t/certs/apisix.key")
- local data = {cert = ssl_cert, key = ssl_key, sni = "test.com", ssl_protocols = {"TLSv1.2", "TLSv1.3"}}
- local code, body = t.test('/apisix/admin/ssls/1',
- ngx.HTTP_PUT,
- core.json.encode(data),
- [[{
- "value": {
- "sni": "test.com",
- "ssl_protocols": ["TLSv1.2", "TLSv1.3"],
- },
- "key": "/apisix/ssls/1"
- }]]
- )
- ngx.status = code
- ngx.say(body)
- }
- }
- --- request
- GET /t
- --- response_body
- passed
- === TEST 7: Set TLSv1.3 for the test2.com
- --- config
- location /t {
- content_by_lua_block {
- local core = require("apisix.core")
- local t = require("lib.test_admin")
- local ssl_cert = t.read_file("t/certs/test2.crt")
- local ssl_key = t.read_file("t/certs/test2.key")
- local data = {cert = ssl_cert, key = ssl_key, sni = "test2.com", ssl_protocols = {"TLSv1.3"}}
- local code, body = t.test('/apisix/admin/ssls/2',
- ngx.HTTP_PUT,
- core.json.encode(data),
- [[{
- "value": {
- "sni": "test2.com"
- },
- "key": "/apisix/ssls/2"
- }]]
- )
- ngx.status = code
- ngx.say(body)
- }
- }
- --- response_body
- passed
- --- request
- GET /t
- === TEST 8: Successfully, access test.com with TLSv1.3
- --- exec
- echo -n "Q" | $OPENSSL_BIN s_client -connect 127.0.0.1:1994 -servername test.com -tls1_3 2>&1 | cat
- --- response_body eval
- qr/Server certificate/
- === TEST 9: Successfully, access test.com with TLSv1.2
- --- exec
- curl -k -v --tls-max 1.2 --tlsv1.2 --resolve "test.com:1994:127.0.0.1" https://test.com:1994/hello 2>&1 | cat
- --- response_body eval
- qr/TLSv1\.2 \(IN\), TLS handshake, Server hello(?s).*hello world/
- === TEST 10: Successfully, access test2.com with TLSv1.3
- --- exec
- echo -n "Q" | $OPENSSL_BIN s_client -connect 127.0.0.1:1994 -servername test2.com -tls1_3 2>&1 | cat
- --- response_body eval
- qr/Server certificate/
- === TEST 11: Failed, access test2.com with TLSv1.2
- --- exec
- curl -k -v --tls-max 1.2 --tlsv1.2 --resolve "test2.com:1994:127.0.0.1" https://test2.com:1994/hello 2>&1 | cat
- --- response_body eval
- qr/TLSv1\.2 \(IN\), TLS alert/
- === TEST 12: set TLSv1.1 for test.com
- --- config
- location /t {
- content_by_lua_block {
- local core = require("apisix.core")
- local t = require("lib.test_admin")
- local ssl_cert = t.read_file("t/certs/apisix.crt")
- local ssl_key = t.read_file("t/certs/apisix.key")
- local data = {cert = ssl_cert, key = ssl_key, sni = "test.com", ssl_protocols = {"TLSv1.1"}}
- local code, body = t.test('/apisix/admin/ssls/1',
- ngx.HTTP_PUT,
- core.json.encode(data),
- [[{
- "value": {
- "sni": "test.com",
- "ssl_protocols": ["TLSv1.1"],
- },
- "key": "/apisix/ssls/1"
- }]]
- )
- ngx.status = code
- ngx.say(body)
- }
- }
- --- request
- GET /t
- --- response_body
- passed
- === TEST 13: Successfully, access test.com with TLSv1.1
- --- exec
- echo -n "Q" | $OPENSSL_BIN s_client -connect 127.0.0.1:1994 -servername test.com -tls1_1 2>&1 | cat
- --- response_body eval
- qr/Server certificate/
- === TEST 14: Failed, access test.com with TLSv1.3
- --- exec
- echo -n "Q" | $OPENSSL_BIN s_client -connect 127.0.0.1:1994 -servername test.com -tls1_3 2>&1 | cat
- --- response_body eval
- qr/tlsv1 alert/
|