@ -433,14 +433,18 @@ function assert_intention_allowed {
local SOURCE = $1
local DESTINATION = $2
[ " $( check_intention " ${ SOURCE } " " ${ DESTINATION } " ) " = = "true" ]
run check_intention " ${ SOURCE } " " ${ DESTINATION } "
[ " $status " -eq 0 ]
[ " $output " = "true" ]
}
function assert_intention_denied {
local SOURCE = $1
local DESTINATION = $2
[ " $( check_intention " ${ SOURCE } " " ${ DESTINATION } " ) " = = "false" ]
run check_intention " ${ SOURCE } " " ${ DESTINATION } "
[ " $status " -eq 0 ]
[ " $output " = "false" ]
}
function docker_consul {
@ -541,7 +545,7 @@ function must_match_in_stats_proxy_response {
# Envoy rather than a connection-level error.
function must_fail_tcp_connection {
# Attempt to curl through upstream
run curl -s -v -f -d hello $1
run curl --no-keepalive - s -v -f -d hello $1
echo " OUTPUT $output "
@ -552,11 +556,20 @@ function must_fail_tcp_connection {
echo " $output " | grep 'Empty reply from server'
}
function must_pass_tcp_connection {
run curl --no-keepalive -s -f -d hello $1
echo " OUTPUT $output "
[ " $status " = = "0" ]
[ " $output " = "hello" ]
}
# must_fail_http_connection see must_fail_tcp_connection but this expects Envoy
# to generate a 503 response since the upstreams have refused connection.
function must_fail_http_connection {
# Attempt to curl through upstream
run curl -s -i -d hello " $1 "
run curl --no-keepalive - s -i -d hello " $1 "
echo " OUTPUT $output "
@ -593,7 +606,7 @@ function must_pass_http_request {
; ;
esac
run retry_default curl -v -s -f $extra_args " $URL "
run curl --no-keepalive -v -s -f $extra_args " $URL "
[ " $status " = = 0 ]
}
@ -627,7 +640,7 @@ function must_fail_http_request {
esac
# Attempt to curl through upstream
run retry_default curl -s -i $extra_args " $URL "
run curl --no-keepalive -s -i $extra_args " $URL "
echo " OUTPUT $output "
@ -681,52 +694,22 @@ function delete_config_entry {
retry_default curl -sL -XDELETE " http://127.0.0.1:8500/v1/config/ ${ KIND } / ${ NAME } "
}
function list_intentions {
curl -s -f "http://localhost:8500/v1/connect/intentions"
}
function get_intention_target_name {
awk -F / '{ if ( NF == 1 ) { print $0 } else { print $2 }}'
}
function get_intention_target_namespace {
awk -F / '{ if ( NF != 1 ) { print $1 } }'
}
function get_intention_by_targets {
function setup_upsert_l4_intention {
local SOURCE = $1
local DESTINATION = $2
local ACTION = $3
local SOURCE_NS = $( get_intention_target_namespace <<< " ${ SOURCE } " )
local SOURCE_NAME = $( get_intention_target_name <<< " ${ SOURCE } " )
local DESTINATION_NS = $( get_intention_target_namespace <<< " ${ DESTINATION } " )
local DESTINATION_NAME = $( get_intention_target_name <<< " ${ DESTINATION } " )
existing = $( list_intentions | jq " .[] | select(.SourceNS == \" $SOURCE_NS \" and .SourceName == \" $SOURCE_NAME \" and .DestinationNS == \" $DESTINATION_NS \" and .DestinationName == \" $DESTINATION_NAME \") " )
if test -z " $existing "
then
return 1
fi
echo " $existing "
return 0
retry_default docker_curl primary -sL -XPUT " http://127.0.0.1:8500/v1/connect/intentions/exact?source= ${ SOURCE } &destination= ${ DESTINATION } " \
-d" {\"Action\": \" ${ ACTION } \"} " >/dev/null
}
function update _intention {
function upsert_l4_intention {
local SOURCE = $1
local DESTINATION = $2
local ACTION = $3
intention = $( get_intention_by_targets " ${ SOURCE } " " ${ DESTINATION } " )
if test $? -ne 0
then
return 1
fi
id = $( jq -r .ID <<< " ${ intention } " )
updated = $( jq " .Action = \" $ACTION \" " <<< " ${ intention } " )
curl -s -X PUT " http://localhost:8500/v1/connect/intentions/ ${ id } " -d " ${ updated } "
return $?
retry_default curl -sL -XPUT " http://127.0.0.1:8500/v1/connect/intentions/exact?source= ${ SOURCE } &destination= ${ DESTINATION } " \
-d" {\"Action\": \" ${ ACTION } \"} " >/dev/null
}
function get_ca_root {