Skip to content

Commit

Permalink
Control DPS endpoint scheme by environmental variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Aug 9, 2024
1 parent d3894e0 commit 0cd4286
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}
Expand Down
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions device-provisioning-service/service/acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 3 additions & 2 deletions device-provisioning-service/service/provision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion device-provisioning-service/test/onboardDpsSim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions device-provisioning-service/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions test/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,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 {
Expand Down
1 change: 1 addition & 0 deletions test/device-provisioning-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions test/device-provisioning-service/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0cd4286

Please sign in to comment.