From ee76f6185b7231e343201a3e463e02f31e55a7f1 Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Fri, 9 Aug 2024 17:20:54 +0200 Subject: [PATCH] Control DPS endpoint scheme by environmental variable --- .github/workflows/test.yml | 2 +- .vscode/settings.json | 2 ++ Makefile | 22 +++++++++++-------- .../service/acls_test.go | 3 +++ .../service/provisionCertificate_test.go | 2 +- .../service/provision_test.go | 5 +++-- .../test/onboardDpsSim.go | 2 +- device-provisioning-service/test/test.go | 5 ++--- test/config/config.go | 7 ++++++ test/device-provisioning-service/Dockerfile | 1 + test/device-provisioning-service/run.sh | 1 + 11 files changed, 35 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d61d35579..7d4db4047 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,7 +131,7 @@ jobs: - name: Remove simulators container if: ${{ always() }} run: | - make simulators/remove + make simulators/remove simulators/bridge/remove simulators/dps/remove - name: Collect cloud server logs when the test fails if: ${{ failure() }} diff --git a/.vscode/settings.json b/.vscode/settings.json index 980a7bd52..e8ee9d754 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -50,11 +50,13 @@ // "TEST_DEVICE_TYPE": "bridged", // "GODEBUG": "scavtrace=1", // "TEST_COAP_GATEWAY_UDP_ENABLED": "true", + // "TEST_DPS_UDP_ENABLED": "false", // "GOMAXPROCS": 1, // "GOFLAGS":"-mod=vendor", // "GRPC_VERBOSITY":"DEBUG", // "GRPC_GO_LOG_VERBOSITY_LEVEL":99, // "GRPC_GO_LOG_SEVERITY_LEVEL":"info", + // "PION_LOG_TRACE=all" }, "go.testTimeout": "600s", "go.buildFlags": [ diff --git a/Makefile b/Makefile index 9b4007801..5f3ca9d3a 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,7 @@ TEST_DATABASE ?= mongodb TEST_LEAD_RESOURCE_TYPE_FILTER ?= TEST_LEAD_RESOURCE_TYPE_REGEX_FILTER ?= TEST_LEAD_RESOURCE_TYPE_USE_UUID ?= false +TEST_DPS_UDP_ENABLED ?= false # supported values: ECDSA-SHA256, ECDSA-SHA384, ECDSA-SHA512 CERT_TOOL_SIGN_ALG ?= ECDSA-SHA256 # supported values: P256, P384, P521 @@ -329,20 +330,21 @@ endef simulators/bridge: simulators/bridge/env $(call RUN-BRIDGE-DOCKER-DEVICE) - .PHONY: simulators/bridge -simulators/bridge/clean: +simulators/bridge/remove: rm -rf $(WORKING_DIRECTORY)/.tmp/bridge || : - $(call REMOVE-DOCKER-DEVICE,$(BRIDGE_DEVICE_NAME)) +.PHONY: simulators/bridge/remove +simulators/bridge/clean: simulators/bridge/remove + $(call REMOVE-DOCKER-DEVICE,$(BRIDGE_DEVICE_NAME)) .PHONY: simulators/bridge/clean simulators: simulators/bridge simulators/clean: simulators/bridge/clean # device provisioning service -ifeq ($(TEST_COAP_GATEWAY_UDP_ENABLED),true) +ifeq ($(TEST_DPS_UDP_ENABLED),true) DPS_ENDPOINT ?= coaps://127.0.0.1:20030 else DPS_ENDPOINT ?= coaps+tcp://127.0.0.1:20030 @@ -378,11 +380,13 @@ define RUN-DPS-DOCKER-DEVICE --log-level $(DPS_DEVICE_LOG_LEVEL) --oc-log-level $(DPS_DEVICE_OC_LOG_LEVEL) $(3) endef - -simulators/dps/clean: +simulators/dps/remove: $(call REMOVE-DOCKER-DEVICE,$(DPS_DEVICE_SIMULATOR_NAME)) - $(call CLEAN-DOCKER-DEVICE,$(DPS_DEVICE_SIMULATOR_NAME)) $(call REMOVE-DOCKER-DEVICE,$(DPS_DEVICE_SIMULATOR_OBT_NAME)) +.PHONY: simulators/dps/remove + +simulators/dps/clean: simulators/dps/remove + $(call CLEAN-DOCKER-DEVICE,$(DPS_DEVICE_SIMULATOR_NAME)) $(call CLEAN-DOCKER-DEVICE,$(DPS_DEVICE_SIMULATOR_OBT_NAME)) .PHONY: simulators/dps/clean @@ -509,7 +513,7 @@ test: env hub-test TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY) \ TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \ TEST_LEAD_RESOURCE_TYPE_FILTER=$(TEST_LEAD_RESOURCE_TYPE_FILTER) TEST_LEAD_RESOURCE_TYPE_REGEX_FILTER='$(TEST_LEAD_RESOURCE_TYPE_REGEX_FILTER)' TEST_LEAD_RESOURCE_TYPE_USE_UUID=$(TEST_LEAD_RESOURCE_TYPE_USE_UUID) \ - TEST_DATABASE=$(TEST_DATABASE)) + TEST_DPS_UDP_ENABLED=$(TEST_DPS_UDP_ENABLED) TEST_DATABASE=$(TEST_DATABASE)) ifeq ($(TEST_COAP_GATEWAY_UDP_ENABLED),true) @$(call RUN-TESTS-UDP) endif @@ -556,7 +560,7 @@ $(test-targets): %: env hub-test TEST_IDENTITY_STORE_LOG_LEVEL=$(TEST_IDENTITY_STORE_LOG_LEVEL) TEST_IDENTITY_STORE_LOG_DUMP_BODY=$(TEST_IDENTITY_STORE_LOG_DUMP_BODY) \ TEST_SNIPPET_SERVICE_LOG_LEVEL=$(TEST_SNIPPET_SERVICE_LOG_LEVEL) TEST_SNIPPET_SERVICE_LOG_DUMP_BODY=$(TEST_SNIPPET_SERVICE_LOG_DUMP_BODY) \ TEST_LEAD_RESOURCE_TYPE_FILTER=$(TEST_LEAD_RESOURCE_TYPE_FILTER) TEST_LEAD_RESOURCE_TYPE_REGEX_FILTER='$(TEST_LEAD_RESOURCE_TYPE_REGEX_FILTER)' TEST_LEAD_RESOURCE_TYPE_USE_UUID=$(TEST_LEAD_RESOURCE_TYPE_USE_UUID) \ - TEST_DATABASE=$(TEST_DATABASE)) + TEST_DPS_UDP_ENABLED=$(TEST_DPS_UDP_ENABLED) TEST_DATABASE=$(TEST_DATABASE)) .PHONY: $(test-targets) diff --git a/device-provisioning-service/service/acls_test.go b/device-provisioning-service/service/acls_test.go index 47cd45bbc..1becd94fe 100644 --- a/device-provisioning-service/service/acls_test.go +++ b/device-provisioning-service/service/acls_test.go @@ -21,6 +21,7 @@ func TestAclsTCP(t *testing.T) { hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) + dpsCfg.APIs.COAP.Protocols = []pkgCoapService.Protocol{pkgCoapService.TCP} shutDown := test.New(t, dpsCfg) defer shutDown() @@ -48,6 +49,8 @@ func TestAclsUDP(t *testing.T) { hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) + dpsCfg.APIs.COAP.Protocols = []pkgCoapService.Protocol{pkgCoapService.UDP} + dpsCfg.APIs.COAP.BlockwiseTransfer.Enabled = true shutDown := test.New(t, dpsCfg) defer shutDown() diff --git a/device-provisioning-service/service/provisionCertificate_test.go b/device-provisioning-service/service/provisionCertificate_test.go index 6ebd04915..e31204596 100644 --- a/device-provisioning-service/service/provisionCertificate_test.go +++ b/device-provisioning-service/service/provisionCertificate_test.go @@ -304,7 +304,7 @@ func TestOwnerWithUnknownCertificateAuthority(t *testing.T) { }, }) - dpsEndpoint := config.ACTIVE_COAP_SCHEME + "://" + dpcCfg.APIs.COAP.Addr + dpsEndpoint := config.ACTIVE_DPS_SCHEME + "://" + dpcCfg.APIs.COAP.Addr err = devClient.UpdateResource(ctx, deviceID, test.ResourcePlgdDpsHref, test.ResourcePlgdDps{Endpoint: &dpsEndpoint}, nil) require.NoError(t, err) diff --git a/device-provisioning-service/service/provision_test.go b/device-provisioning-service/service/provision_test.go index 5524ce388..64b1085e8 100644 --- a/device-provisioning-service/service/provision_test.go +++ b/device-provisioning-service/service/provision_test.go @@ -118,7 +118,8 @@ func TestProvisioning(t *testing.T) { require.NotEmpty(t, got[0].GetDeviceId()) require.NotEmpty(t, got[0].GetEnrollmentGroupId()) require.NotEmpty(t, got[0].GetCreationDate()) - if !config.COAP_GATEWAY_UDP_ENABLED { + if !config.DPS_UDP_ENABLED { + // TODO: fix in iotivity-lite? no local endpoints reported for UDP require.NotEmpty(t, got[0].GetLocalEndpoints()) } require.NotEmpty(t, got[0].GetAcl().GetAccessControlList()) @@ -468,7 +469,7 @@ func TestProvisioningFromNewDPSAddress(t *testing.T) { }() // Update DPS address in device - endpoint := config.ACTIVE_COAP_SCHEME + "://" + dpsCfg.APIs.COAP.Addr + endpoint := config.ACTIVE_DPS_SCHEME + "://" + dpsCfg.APIs.COAP.Addr err = pskConn.UpdateResource(ctx, test.ResourcePlgdDpsHref, test.ResourcePlgdDps{Endpoint: &endpoint}, nil) require.NoError(t, err) diff --git a/device-provisioning-service/test/onboardDpsSim.go b/device-provisioning-service/test/onboardDpsSim.go index 3bdde4164..0a22c1df1 100644 --- a/device-provisioning-service/test/onboardDpsSim.go +++ b/device-provisioning-service/test/onboardDpsSim.go @@ -255,7 +255,7 @@ func OnboardDpsSimDevice(ctx context.Context, t *testing.T, gc pb.GrpcGatewayCli onboard := func() { var v interface{} - endpoint := config.ACTIVE_COAP_SCHEME + "://" + dpsEndpoint + endpoint := config.ACTIVE_DPS_SCHEME + "://" + dpsEndpoint err = devClient.UpdateResource(ctx, d.GetID(), ResourcePlgdDpsHref, ResourcePlgdDps{Endpoint: &endpoint}, &v) require.NoError(t, err) } diff --git a/device-provisioning-service/test/test.go b/device-provisioning-service/test/test.go index 506df2946..e09cf481d 100644 --- a/device-provisioning-service/test/test.go +++ b/device-provisioning-service/test/test.go @@ -198,14 +198,13 @@ func MakeConfig(t require.TestingT) service.Config { cfg.APIs.COAP.MaxMessageSize = 256 * 1024 cfg.APIs.COAP.MessagePoolSize = 1000 cfg.APIs.COAP.Protocols = []pkgCoapService.Protocol{pkgCoapService.TCP} - if config.COAP_GATEWAY_UDP_ENABLED { + if config.DPS_UDP_ENABLED { cfg.APIs.COAP.Protocols = append(cfg.APIs.COAP.Protocols, pkgCoapService.UDP) } cfg.APIs.COAP.InactivityMonitor = &pkgCoapService.InactivityMonitor{ Timeout: time.Second * 20, } - cfg.APIs.COAP.BlockwiseTransfer.Enabled = config.COAP_GATEWAY_UDP_ENABLED - cfg.APIs.COAP.BlockwiseTransfer.Enabled = true + cfg.APIs.COAP.BlockwiseTransfer.Enabled = config.DPS_UDP_ENABLED cfg.APIs.COAP.BlockwiseTransfer.SZX = "1024" cfg.APIs.HTTP = MakeHTTPConfig() tlsServerCfg := config.MakeTLSServerConfig() diff --git a/test/config/config.go b/test/config/config.go index 5511fcd79..4bc83e9a3 100644 --- a/test/config/config.go +++ b/test/config/config.go @@ -80,6 +80,13 @@ var ( } return string(schema.TCPSecureScheme) }() + DPS_UDP_ENABLED = os.Getenv("TEST_DPS_UDP_ENABLED") == TRUE_STRING + ACTIVE_DPS_SCHEME = func() string { + if os.Getenv("TEST_DPS_UDP_ENABLED") == TRUE_STRING { + return string(schema.UDPSecureScheme) + } + return string(schema.TCPSecureScheme) + }() SCYLLA_HOSTS = []string{"127.0.0.1"} SCYLLA_PORT = pkgCqldb.DefaultPort ACTIVE_DATABASE = func() database.DBUse { diff --git a/test/device-provisioning-service/Dockerfile b/test/device-provisioning-service/Dockerfile index fa5722f13..3e19c278e 100644 --- a/test/device-provisioning-service/Dockerfile +++ b/test/device-provisioning-service/Dockerfile @@ -92,5 +92,6 @@ ENV CERT_TOOL_ELLIPTIC_CURVE=P256 ENV MONGO_PORT=27017 ENV NATS_PORT=4222 # ENV COAP_GATEWAY_UDP_ENABLED=false +# ENV DPS_UDP_ENABLED=false ENTRYPOINT ["/usr/local/bin/run.sh"] diff --git a/test/device-provisioning-service/run.sh b/test/device-provisioning-service/run.sh index 1a0fff018..3144a1151 100755 --- a/test/device-provisioning-service/run.sh +++ b/test/device-provisioning-service/run.sh @@ -221,6 +221,7 @@ if [ "${RUN}" = "true" ]; then export TEST_DPS_ROOT_CA_KEY_ALT="${CA_POOL_CERT_KEY_ALT_PATH}" export M2M_OAUTH_SERVER_PRIVATE_KEY="${OAUTH_KEYS_PATH}/m2mAccessTokenKey.pem" export TEST_COAP_GATEWAY_UDP_ENABLED="${COAP_GATEWAY_UDP_ENABLED}" + export TEST_DPS_UDP_ENABLED="${DPS_UDP_ENABLED}" echo "starting dps-service test" dps-service.test -test.v -test.timeout 1200s