Skip to content

Commit

Permalink
add acc tests for tcp monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
biscout42 committed Aug 13, 2024
1 parent f105d97 commit cc827e8
Show file tree
Hide file tree
Showing 9 changed files with 674 additions and 59 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ jobs:
- name: Lint
run: make lint

- name: Check env
run: |-
pwd
ls -la ${{ github.workspace }}/kibana-config
echo "${{ github.workspace }}"
test:
name: Matrix Acceptance Test
needs: build
Expand Down Expand Up @@ -87,7 +81,6 @@ jobs:
ELASTICSEARCH_PASSWORD: ${{ env.KIBANA_SYSTEM_PASSWORD }}
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: a7a6311933d3503b89bc2dbc36572c33a6c10925682e591bffcab6911c06786d
LOGGING_ROOT_LEVEL: debug
XPACK_FLEET_ENABLED: true
ports:
- 5601:5601
options: --health-cmd="curl http://localhost:5601/api/status" --health-interval=10s --health-timeout=5s --health-retries=10
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ docker-kibana: docker-network docker-elasticsearch set-kibana-password ## Start
-e ELASTICSEARCH_USERNAME=$(KIBANA_SYSTEM_USERNAME) \
-e ELASTICSEARCH_PASSWORD=$(KIBANA_SYSTEM_PASSWORD) \
-e XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY=a7a6311933d3503b89bc2dbc36572c33a6c10925682e591bffcab6911c06786d \
-e "xpack.fleet.enabled=true" \
-v ./kibana-config/:/usr/share/kibana/config/ \
-e LOGGING_ROOT_LEVEL=debug \
--name $(KIBANA_NAME) \
--network $(ELASTICSEARCH_NETWORK) \
docker.elastic.co/kibana/kibana:$(STACK_VERSION); \
Expand All @@ -158,7 +157,7 @@ docker-kibana-with-tls: docker-network docker-elasticsearch set-kibana-password
-e SERVER_SSL_CERTIFICATE=/certs/localhost+1.pem \
-e SERVER_SSL_KEY=/certs/localhost+1-key.pem \
-e SERVER_SSL_ENABLED=true \
-e "logging.root.level=debug" \
-e LOGGING_ROOT_LEVEL=debug \
--name $(KIBANA_NAME) \
--network $(ELASTICSEARCH_NETWORK) \
docker.elastic.co/kibana/kibana:$(STACK_VERSION); \
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/kibana_synthetics_monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ Required:

Optional:

- `check_receive` (String) The expected answer.
- `check_send` (String) An optional payload string to send to the remote host.
- `proxy_url` (String) The URL of the SOCKS5 proxy to use when connecting to the server. The value must be a URL with a scheme of `socks5://`. If the SOCKS5 proxy server requires client authentication, then a username and password can be embedded in the URL. When using a proxy, hostnames are resolved on the proxy server instead of on the client. You can change this behavior by setting the `proxy_use_local_resolver` option.
- `proxy_use_local_resolver` (Boolean) A Boolean value that determines whether hostnames are resolved locally instead of being resolved on the proxy server. The default value is false, which means that name resolution occurs on the proxy server.
- `ssl_supported_protocols` (List of String) List of allowed SSL/TLS versions.
Expand Down
140 changes: 130 additions & 10 deletions internal/kibana/synthetics/acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var (

const (
httpMonitorId = "elasticstack_kibana_synthetics_monitor.http-monitor"
tcpMonitorId = "elasticstack_kibana_synthetics_monitor.tcp-monitor"

providerConfig = `
provider "elasticstack" {
Expand Down Expand Up @@ -101,26 +102,77 @@ resource "elasticstack_kibana_synthetics_monitor" "http-monitor" {
mode = "all"
ipv4 = true
ipv6 = true
proxy_url = ""
proxy_url = "http://localhost"
}
}
`

/*
check.send = "Hello"
check.receive = "World"
tcpMonitorConfig = `
resource "elasticstack_kibana_synthetics_monitor" "tcp-monitor" {
name = "TestTcpMonitorResource"
space_id = "default"
schedule = 5
private_locations = [elasticstack_kibana_synthetics_private_location.test.label]
enabled = true
tags = ["a", "b"]
alert = {
status = {
enabled = true
}
tls = {
enabled = true
}
}
service_name = "test apm service"
timeout = 30
tcp = {
host = "http://localhost:5601"
ssl_verification_mode = "full"
ssl_supported_protocols = ["TLSv1.0", "TLSv1.1", "TLSv1.2"]
proxy_url = "http://localhost:8080"
proxy_use_local_resolver = true
}
}
`

tcpMonitorUpdated = `
resource "elasticstack_kibana_synthetics_monitor" "tcp-monitor" {
name = "TestTcpMonitorResource Updated"
space_id = "default"
schedule = 10
private_locations = [elasticstack_kibana_synthetics_private_location.test.label]
enabled = false
tags = ["c", "d", "e"]
alert = {
status = {
enabled = true
}
tls = {
enabled = false
}
}
service_name = "test apm service"
timeout = 30
tcp = {
host = "http://localhost:8080"
ssl_verification_mode = "full"
ssl_supported_protocols = ["TLSv1.2"]
proxy_url = "http://localhost"
proxy_use_local_resolver = false
}
}
*/
`
)

func TestSyntheticMonitorResource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.Providers,
Steps: []resource.TestStep{
// Create and Read testing
// Create and Read http monitor
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaVersion),
Config: providerConfig + privateLocationConfig + httpMonitorConfig,
Expand Down Expand Up @@ -160,7 +212,7 @@ func TestSyntheticMonitorResource(t *testing.T) {
ImportStateVerify: true,
Config: providerConfig + privateLocationConfig + httpMonitorConfig,
},
// Update and Read testing
// Update and Read testing http monitor
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaVersion),
ResourceName: httpMonitorId,
Expand All @@ -176,20 +228,88 @@ func TestSyntheticMonitorResource(t *testing.T) {
resource.TestCheckResourceAttr(httpMonitorId, "tags.#", "3"),
resource.TestCheckResourceAttr(httpMonitorId, "tags.0", "c"),
resource.TestCheckResourceAttr(httpMonitorId, "tags.1", "d"),
resource.TestCheckResourceAttr(httpMonitorId, "tags.1", "e"),
resource.TestCheckResourceAttr(httpMonitorId, "tags.2", "e"),
resource.TestCheckResourceAttr(httpMonitorId, "alert.status.enabled", "true"),
resource.TestCheckResourceAttr(httpMonitorId, "alert.tls.enabled", "false"),
resource.TestCheckResourceAttr(httpMonitorId, "service_name", "test apm service"),
resource.TestCheckResourceAttr(httpMonitorId, "timeout", "30"),
resource.TestCheckResourceAttr(httpMonitorId, "http.url", "http://localhost:8080"),
resource.TestCheckResourceAttr(httpMonitorId, "http.ssl_verification_mode", "full"),
resource.TestCheckResourceAttr(httpMonitorId, "http.ssl_supported_protocols.#", "1"),
resource.TestCheckResourceAttr(httpMonitorId, "http.ssl_supported_protocols.2", "TLSv1.2"),
resource.TestCheckResourceAttr(httpMonitorId, "http.ssl_supported_protocols.0", "TLSv1.2"),
resource.TestCheckResourceAttr(httpMonitorId, "http.max_redirects", "10"),
resource.TestCheckResourceAttr(httpMonitorId, "http.mode", "all"),
resource.TestCheckResourceAttr(httpMonitorId, "http.ipv4", "true"),
resource.TestCheckResourceAttr(httpMonitorId, "http.ipv6", "true"),
resource.TestCheckNoResourceAttr(httpMonitorId, "http.proxy_url"),
resource.TestCheckResourceAttr(httpMonitorId, "http.proxy_url", "http://localhost"),
resource.TestCheckNoResourceAttr(httpMonitorId, "tcp"),
),
},
// Create and Read tcp monitor
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaVersion),
Config: providerConfig + privateLocationConfig + tcpMonitorConfig,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(tcpMonitorId, "id"),
resource.TestCheckResourceAttr(tcpMonitorId, "name", "TestTcpMonitorResource"),
resource.TestCheckResourceAttr(tcpMonitorId, "space_id", "default"),
resource.TestCheckResourceAttr(tcpMonitorId, "schedule", "5"),
resource.TestCheckResourceAttr(tcpMonitorId, "private_locations.#", "1"),
resource.TestCheckResourceAttrSet(tcpMonitorId, "private_locations.0"),
resource.TestCheckResourceAttr(tcpMonitorId, "enabled", "true"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.#", "2"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.0", "a"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.1", "b"),
resource.TestCheckResourceAttr(tcpMonitorId, "alert.status.enabled", "true"),
resource.TestCheckResourceAttr(tcpMonitorId, "alert.tls.enabled", "true"),
resource.TestCheckResourceAttr(tcpMonitorId, "service_name", "test apm service"),
resource.TestCheckResourceAttr(tcpMonitorId, "timeout", "30"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.host", "http://localhost:5601"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_verification_mode", "full"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_supported_protocols.#", "3"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_supported_protocols.0", "TLSv1.0"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_supported_protocols.1", "TLSv1.1"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_supported_protocols.2", "TLSv1.2"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.proxy_url", "http://localhost:8080"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.proxy_use_local_resolver", "true"),
),
},
// ImportState testing
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaVersion),
ResourceName: tcpMonitorId,
ImportState: true,
ImportStateVerify: true,
Config: providerConfig + privateLocationConfig + tcpMonitorConfig,
},
// Update and Read tcp monitor
{
SkipFunc: versionutils.CheckIfVersionIsUnsupported(minKibanaVersion),
ResourceName: tcpMonitorId,
Config: providerConfig + privateLocationConfig + tcpMonitorUpdated,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(tcpMonitorId, "id"),
resource.TestCheckResourceAttr(tcpMonitorId, "name", "TestTcpMonitorResource Updated"),
resource.TestCheckResourceAttr(tcpMonitorId, "space_id", "default"),
resource.TestCheckResourceAttr(tcpMonitorId, "schedule", "10"),
resource.TestCheckResourceAttr(tcpMonitorId, "private_locations.#", "1"),
resource.TestCheckResourceAttrSet(tcpMonitorId, "private_locations.0"),
resource.TestCheckResourceAttr(tcpMonitorId, "enabled", "false"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.#", "3"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.0", "c"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.1", "d"),
resource.TestCheckResourceAttr(tcpMonitorId, "tags.2", "e"),
resource.TestCheckResourceAttr(tcpMonitorId, "alert.status.enabled", "true"),
resource.TestCheckResourceAttr(tcpMonitorId, "alert.tls.enabled", "false"),
resource.TestCheckResourceAttr(tcpMonitorId, "service_name", "test apm service"),
resource.TestCheckResourceAttr(tcpMonitorId, "timeout", "30"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.host", "http://localhost:8080"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_verification_mode", "full"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_supported_protocols.#", "1"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.ssl_supported_protocols.0", "TLSv1.2"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.proxy_url", "http://localhost"),
resource.TestCheckResourceAttr(tcpMonitorId, "tcp.proxy_use_local_resolver", "false"),
resource.TestCheckNoResourceAttr(tcpMonitorId, "http"),
),
},
// Delete testing automatically occurs in TestCase
Expand Down
33 changes: 17 additions & 16 deletions internal/kibana/synthetics/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ type tfTCPMonitorFieldsV0 struct {
Host types.String `tfsdk:"host"`
SslVerificationMode types.String `tfsdk:"ssl_verification_mode"`
SslSupportedProtocols []types.String `tfsdk:"ssl_supported_protocols"`
CheckSend types.String `tfsdk:"check_send"`
CheckReceive types.String `tfsdk:"check_receive"`
ProxyURL types.String `tfsdk:"proxy_url"`
ProxyUseLocalResolver types.Bool `tfsdk:"proxy_use_local_resolver"`
// commented out due-to https://github.com/elastic/kibana/issues/189906
//CheckSend types.String `tfsdk:"check_send"`
//CheckReceive types.String `tfsdk:"check_receive"`
ProxyURL types.String `tfsdk:"proxy_url"`
ProxyUseLocalResolver types.Bool `tfsdk:"proxy_use_local_resolver"`
}

type tfModelV0 struct {
Expand Down Expand Up @@ -273,14 +274,14 @@ func tcpMonitorFieldsSchema() schema.Attribute {
Optional: true,
MarkdownDescription: "List of allowed SSL/TLS versions.",
},
"check_send": schema.StringAttribute{
Optional: true,
MarkdownDescription: "An optional payload string to send to the remote host.",
},
"check_receive": schema.StringAttribute{
Optional: true,
MarkdownDescription: "The expected answer. ",
},
//"check_send": schema.StringAttribute{
// Optional: true,
// MarkdownDescription: "An optional payload string to send to the remote host.",
//},
//"check_receive": schema.StringAttribute{
// Optional: true,
// MarkdownDescription: "The expected answer. ",
//},
"proxy_url": schema.StringAttribute{
Optional: true,
MarkdownDescription: "The URL of the SOCKS5 proxy to use when connecting to the server. The value must be a URL with a scheme of `socks5://`. If the SOCKS5 proxy server requires client authentication, then a username and password can be embedded in the URL. When using a proxy, hostnames are resolved on the proxy server instead of on the client. You can change this behavior by setting the `proxy_use_local_resolver` option.",
Expand Down Expand Up @@ -446,8 +447,8 @@ func toTfTCPMonitorFieldsV0(api *kbapi.SyntheticsMonitor) (*tfTCPMonitorFieldsV0
Host: types.StringValue(api.Host),
SslVerificationMode: types.StringValue(api.SslVerificationMode),
SslSupportedProtocols: StringSliceValue(api.SslSupportedProtocols),
CheckSend: types.StringValue(api.CheckSend),
CheckReceive: types.StringValue(api.CheckReceive),
//CheckSend: types.StringValue(api.CheckSend),
//CheckReceive: types.StringValue(api.CheckReceive),
ProxyURL: types.StringValue(api.ProxyUrl),
ProxyUseLocalResolver: types.BoolPointerValue(api.ProxyUseLocalResolver),
}, nil
Expand Down Expand Up @@ -586,8 +587,8 @@ func (v *tfModelV0) toTCPMonitorFields() kbapi.MonitorFields {
Host: v.TCP.Host.ValueString(),
SslVerificationMode: v.TCP.SslVerificationMode.ValueString(),
SslSupportedProtocols: ValueStringSlice(v.TCP.SslSupportedProtocols),
CheckSend: v.TCP.CheckSend.ValueString(),
CheckReceive: v.TCP.CheckReceive.ValueString(),
//CheckSend: v.TCP.CheckSend.ValueString(),
//CheckReceive: v.TCP.CheckReceive.ValueString(),
ProxyUrl: v.TCP.ProxyURL.ValueString(),
ProxyUseLocalResolver: v.TCP.ProxyUseLocalResolver.ValueBoolPointer(),
}
Expand Down
18 changes: 9 additions & 9 deletions internal/kibana/synthetics/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func TestToModelV0(t *testing.T) {
TCP: &tfTCPMonitorFieldsV0{
Host: types.StringValue(""),
SslVerificationMode: types.StringValue(""),
CheckSend: types.StringValue(""),
CheckReceive: types.StringValue(""),
ProxyURL: types.StringValue(""),
//CheckSend: types.StringValue(""),
//CheckReceive: types.StringValue(""),
ProxyURL: types.StringValue(""),
},
},
},
Expand Down Expand Up @@ -189,8 +189,8 @@ func TestToModelV0(t *testing.T) {
Host: types.StringValue("example.com:9200"),
SslVerificationMode: types.StringValue("full"),
SslSupportedProtocols: []types.String{types.StringValue("TLSv1.2"), types.StringValue("TLSv1.3")},
CheckSend: types.StringValue("hello"),
CheckReceive: types.StringValue("world"),
//CheckSend: types.StringValue("hello"),
//CheckReceive: types.StringValue("world"),
ProxyURL: types.StringValue("http://proxy.com"),
ProxyUseLocalResolver: types.BoolPointerValue(tBool),
},
Expand Down Expand Up @@ -314,8 +314,8 @@ func TestToKibanaAPIRequest(t *testing.T) {
Host: types.StringValue("example.com:9200"),
SslVerificationMode: types.StringValue("full"),
SslSupportedProtocols: []types.String{types.StringValue("TLSv1.2"), types.StringValue("TLSv1.3")},
CheckSend: types.StringValue("hello"),
CheckReceive: types.StringValue("world"),
//CheckSend: types.StringValue("hello"),
//CheckReceive: types.StringValue("world"),
ProxyURL: types.StringValue("http://proxy.com"),
ProxyUseLocalResolver: types.BoolPointerValue(tBool),
},
Expand All @@ -338,8 +338,8 @@ func TestToKibanaAPIRequest(t *testing.T) {
Host: "example.com:9200",
SslVerificationMode: "full",
SslSupportedProtocols: []string{"TLSv1.2", "TLSv1.3"},
CheckSend: "hello",
CheckReceive: "world",
//CheckSend: "hello",
//CheckReceive: "world",
ProxyUrl: "http://proxy.com",
ProxyUseLocalResolver: tBool,
},
Expand Down
11 changes: 0 additions & 11 deletions kibana-config/kibana.yml

This file was deleted.

1 change: 0 additions & 1 deletion libs/go-kibana-rest/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ services:
ELASTICSEARCH_USERNAME: kibana_system
ELASTICSEARCH_PASSWORD: changeme
XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY: min-32-byte-long-strong-encryption-key
xpack.fleet.enabled: true
links:
- elasticsearch:es
ports:
Expand Down
Loading

0 comments on commit cc827e8

Please sign in to comment.