From 719522d0014ab3f25da4c42a49a65fd4f3c69c5f Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Mon, 12 Aug 2024 13:57:48 +0200 Subject: [PATCH] fixup! Integrate with bundle --- .github/workflows/test.yml | 4 + bundle/Dockerfile | 2 + bundle/run.sh | 382 +++--------------- .../service/acls_test.go | 4 +- .../service/auth_test.go | 2 +- .../service/cloudConfiguration_test.go | 4 +- .../service/credentials_test.go | 4 +- .../service/http/getRegistrations_test.go | 2 +- .../service/memory_test.go | 2 +- .../service/ownership_test.go | 2 +- .../service/plgdTime_test.go | 2 +- .../service/provisionCertificate_test.go | 12 +- .../service/provisionFail_test.go | 13 +- .../service/provisionRecovery_test.go | 5 +- .../service/provisionRestart_test.go | 8 +- .../service/provisionRetry_test.go | 4 +- .../service/provision_test.go | 20 +- .../service/service.go | 5 +- .../service/service_test.go | 6 +- 19 files changed, 118 insertions(+), 365 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d4db4047..81164ac12 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -98,6 +98,10 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: + - name: Ports + run: | + sudo netstat -tulpn | grep LISTEN + - name: CPU Info run: | cat /proc/cpuinfo diff --git a/bundle/Dockerfile b/bundle/Dockerfile index fbd403bc3..3f7b46d7f 100644 --- a/bundle/Dockerfile +++ b/bundle/Dockerfile @@ -203,6 +203,8 @@ COPY --from=build /go/bin/snippet-service /usr/local/bin/snippet-service COPY --from=build /go/src/github.com/plgd-dev/hub/snippet-service/config.yaml /configs/snippet-service.yaml COPY --from=build /go/bin/grpc-reflection /usr/local/bin/grpc-reflection COPY --from=build /go/src/github.com/plgd-dev/hub/tools/grpc-reflection/config.yaml /configs/grpc-reflection.yaml +COPY --from=build /go/bin/device-provisioning-service /usr/local/bin/device-provisioning-service +COPY --from=build /go/src/github.com/plgd-dev/hub/device-provisioning-service/config.yaml /configs/device-provisioning-service.yaml # install scylla RUN curl -sSf get.scylladb.com/server | sudo bash -s -- --scylla-version 5.4 diff --git a/bundle/run.sh b/bundle/run.sh index e672039a1..cf1b3830c 100755 --- a/bundle/run.sh +++ b/bundle/run.sh @@ -182,340 +182,78 @@ if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${CA_POOL}" ]; then fi # copy ceritficates to paths -## oauth-server -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/oauth-server.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/oauth-server.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/oauth-server.yaml | sort | uniq) +function copy_ca_pools() { + CONFIG_FILE=$1 + + while read -r line; do + file=`echo $line | yq e '.[0]' - ` + mkdir -p `dirname ${file}` + if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then + cp $CA_POOL ${file} + fi + done < <(yq e '[.. | select(has("caPool")) | .caPool]' "${CONFIG_FILE}" | sort | uniq) +} -## m2m-oauth-server -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/m2m-oauth-server.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/m2m-oauth-server.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/m2m-oauth-server.yaml | sort | uniq) +function copy_certificates() { + CONFIG_FILE=$1 -## identity-store -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/identity-store.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/identity-store.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/identity-store.yaml | sort | uniq) + while read -r line; do + file=`echo $line | yq e '.[0]' - ` + mkdir -p `dirname ${file}` + if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then + cp $CERT_FILE ${file} + fi + done < <(yq e '[.. | select(has("certFile")) | .certFile]' "${CONFIG_FILE}" | sort | uniq) +} -## resource-aggregate -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/resource-aggregate.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/resource-aggregate.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/resource-aggregate.yaml | sort | uniq) +function copy_private_keys() { + CONFIG_FILE=$1 -## resource-directory -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/resource-directory.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/resource-directory.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/resource-directory.yaml | sort | uniq) + while read -r line; do + file=`echo $line | yq e '.[0]' - ` + mkdir -p `dirname ${file}` + if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then + cp $KEY_FILE ${file} + fi + done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' "${CONFIG_FILE}" | sort | uniq) +} -## coap-gateway -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/coap-gateway.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/coap-gateway.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/coap-gateway.yaml | sort | uniq) +function copy_keys_and_certificates() { + CONFIG_FILE=$1 -## grpc-gateway -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/grpc-gateway.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/grpc-gateway.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/grpc-gateway.yaml | sort | uniq) + copy_ca_pools "${CONFIG_FILE}" + copy_certificates "${CONFIG_FILE}" + copy_private_keys "${CONFIG_FILE}" +} +## oauth-server +copy_keys_and_certificates /configs/oauth-server.yaml +## m2m-oauth-server +copy_keys_and_certificates /configs/m2m-oauth-server.yaml +## identity-store +copy_keys_and_certificates /configs/identity-store.yaml +## resource-aggregate +copy_keys_and_certificates /configs/resource-aggregate.yaml +## resource-directory +copy_keys_and_certificates /configs/resource-directory.yaml +## coap-gateway +copy_keys_and_certificates /configs/coap-gateway.yaml +## grpc-gateway +copy_keys_and_certificates /configs/grpc-gateway.yaml ## http-gateway -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/http-gateway.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/http-gateway.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/http-gateway.yaml | sort | uniq) - +copy_keys_and_certificates /configs/http-gateway.yaml ## certificate-authority -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/certificate-authority.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/certificate-authority.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/certificate-authority.yaml | sort | uniq) - +copy_keys_and_certificates /configs/certificate-authority.yaml ## cloud2cloud-gateway -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/cloud2cloud-gateway.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/cloud2cloud-gateway.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/cloud2cloud-gateway.yaml | sort | uniq) - +copy_keys_and_certificates /configs/cloud2cloud-gateway.yaml ## cloud2cloud-connector -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/cloud2cloud-connector.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/cloud2cloud-connector.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/cloud2cloud-connector.yaml | sort | uniq) - +copy_keys_and_certificates /configs/cloud2cloud-connector.yaml ## snippet-service -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/snippet-service.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/snippet-service.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/snippet-service.yaml| sort | uniq) - +copy_keys_and_certificates /configs/snippet-service.yaml ## grpc-reflection -### setup root-cas -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CA_POOL ${file} - fi -done < <(yq e '[.. | select(has("caPool")) | .caPool]' /configs/grpc-reflection.yaml | sort | uniq) -### setup certificates -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $CERT_FILE ${file} - fi -done < <(yq e '[.. | select(has("certFile")) | .certFile]' /configs/grpc-reflection.yaml | sort | uniq) -### setup private keys -while read -r line; do - file=`echo $line | yq e '.[0]' - ` - mkdir -p `dirname ${file}` - if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${file}" ]; then - cp $KEY_FILE ${file} - fi -done < <(yq e '[.. | select(has("keyFile")) | .keyFile]' /configs/grpc-reflection.yaml| sort | uniq) +copy_keys_and_certificates /configs/grpc-reflection.yaml +## device-provisioning-service +copy_keys_and_certificates /configs/device-provisioning-service.yaml mkdir -p ${OAUTH_KEYS_PATH} if [ "${OVERRIDE_FILES}" = "true" ] || [ ! -f "${OAUTH_ID_TOKEN_KEY_PATH}" ]; then @@ -1521,7 +1259,7 @@ function checkService() { # This illustrates part of the heavy lifting you need to do if you want to run # more than one service in a container. The container exits with an error # if it detects that either of the processes has exited. -# Otherwise it loops forever, waking up every 60 seconds +# Otherwise it loops forever, waking up every 10 seconds while sleep 10; do checkService $nats_server_pid "nats-server" "$LOGS_PATH/nats-server.log" checkService $mongo_pid "mongod" "$LOGS_PATH/mongod.log" diff --git a/device-provisioning-service/service/acls_test.go b/device-provisioning-service/service/acls_test.go index 1becd94fe..c6b1084ef 100644 --- a/device-provisioning-service/service/acls_test.go +++ b/device-provisioning-service/service/acls_test.go @@ -18,7 +18,7 @@ import ( func TestAclsTCP(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) dpsCfg.APIs.COAP.Protocols = []pkgCoapService.Protocol{pkgCoapService.TCP} @@ -46,7 +46,7 @@ func TestAclsTCP(t *testing.T) { func TestAclsUDP(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) dpsCfg.APIs.COAP.Protocols = []pkgCoapService.Protocol{pkgCoapService.UDP} diff --git a/device-provisioning-service/service/auth_test.go b/device-provisioning-service/service/auth_test.go index 86db93c78..631700586 100644 --- a/device-provisioning-service/service/auth_test.go +++ b/device-provisioning-service/service/auth_test.go @@ -22,7 +22,7 @@ import ( func TestWithUntrustedCertificate(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() caCfg := caService.MakeConfig(t) caCfg.Signer.ExpiresIn = time.Hour * 10 diff --git a/device-provisioning-service/service/cloudConfiguration_test.go b/device-provisioning-service/service/cloudConfiguration_test.go index 13eaaca89..df897688a 100644 --- a/device-provisioning-service/service/cloudConfiguration_test.go +++ b/device-provisioning-service/service/cloudConfiguration_test.go @@ -49,7 +49,7 @@ func GetCredentials(ctx context.Context, t *testing.T, c *coapTcpClient.Conn, de func TestCloudPOST(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) shutDown := test.New(t, dpsCfg) @@ -78,7 +78,7 @@ func TestCloudPOST(t *testing.T) { } func TestInvalidateEnrollmentGroupHubCache(t *testing.T) { - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() store, closeStore := test.NewMongoStore(t) diff --git a/device-provisioning-service/service/credentials_test.go b/device-provisioning-service/service/credentials_test.go index b231f9296..2f14ae225 100644 --- a/device-provisioning-service/service/credentials_test.go +++ b/device-provisioning-service/service/credentials_test.go @@ -82,7 +82,7 @@ func privateKeyToPem(t *testing.T, p *ecdsa.PrivateKey) []byte { func TestCredentials(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() caCfg := caService.MakeConfig(t) caCfg.Signer.ExpiresIn = time.Hour * 10 @@ -157,7 +157,7 @@ const testPSK = "0123456789abcdef" func TestCredentialsWithPSK(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() caCfg := caService.MakeConfig(t) caCfg.Signer.ExpiresIn = time.Hour * 10 diff --git a/device-provisioning-service/service/http/getRegistrations_test.go b/device-provisioning-service/service/http/getRegistrations_test.go index 7204eb611..5d9a4c454 100644 --- a/device-provisioning-service/service/http/getRegistrations_test.go +++ b/device-provisioning-service/service/http/getRegistrations_test.go @@ -75,7 +75,7 @@ func TestDeviceProvisionServiceServerGetProvisioningRecords(t *testing.T) { }, } - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesOAuth) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth) defer hubShutdown() store, closeStore := test.NewMongoStore(t) diff --git a/device-provisioning-service/service/memory_test.go b/device-provisioning-service/service/memory_test.go index 365de4232..4fe8506de 100644 --- a/device-provisioning-service/service/memory_test.go +++ b/device-provisioning-service/service/memory_test.go @@ -87,7 +87,7 @@ func testNConnections(t *testing.T, n int, debugging bool) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() caCfg := caService.MakeConfig(t) caCfg.Signer.ExpiresIn = time.Hour * 10 diff --git a/device-provisioning-service/service/ownership_test.go b/device-provisioning-service/service/ownership_test.go index ab660521c..f339f2cf9 100644 --- a/device-provisioning-service/service/ownership_test.go +++ b/device-provisioning-service/service/ownership_test.go @@ -17,7 +17,7 @@ import ( func TestOwnership(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) shutDown := test.New(t, dpsCfg) diff --git a/device-provisioning-service/service/plgdTime_test.go b/device-provisioning-service/service/plgdTime_test.go index a09c243ac..4a2ce1594 100644 --- a/device-provisioning-service/service/plgdTime_test.go +++ b/device-provisioning-service/service/plgdTime_test.go @@ -15,7 +15,7 @@ import ( func TestPlgdTime(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) shutDown := test.New(t, dpsCfg) diff --git a/device-provisioning-service/service/provisionCertificate_test.go b/device-provisioning-service/service/provisionCertificate_test.go index e31204596..63e7adf8c 100644 --- a/device-provisioning-service/service/provisionCertificate_test.go +++ b/device-provisioning-service/service/provisionCertificate_test.go @@ -52,7 +52,7 @@ func TestProvisioningWithRenewal(t *testing.T) { coapGWCfg := hubCoapGWTest.MakeConfig(t) coapGWCfg.APIs.COAP.TLS.Embedded.ClientCertificateRequired = true coapGWCfg.APIs.COAP.TLS.DisconnectOnExpiredCertificate = false - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway| + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway| hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway, hubTestService.WithCOAPGWConfig(coapGWCfg)) defer hubShutdown() @@ -168,7 +168,7 @@ func TestProvisioningNewCertificateDuringConnectionToHub(t *testing.T) { coapGWCfg := hubCoapGWTest.MakeConfig(t) coapGWCfg.APIs.COAP.TLS.Embedded.ClientCertificateRequired = true coapGWCfg.APIs.COAP.TLS.DisconnectOnExpiredCertificate = false - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway| + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway| hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway, hubTestService.WithCOAPGWConfig(coapGWCfg)) defer hubShutdown() @@ -253,7 +253,7 @@ func TestProvisioningNewCertificateDuringConnectionToHub(t *testing.T) { func TestOwnerWithUnknownCertificateAuthority(t *testing.T) { defer test.ClearDB(t) hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory| - hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate| + hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate| hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() @@ -435,9 +435,9 @@ func findSecureUDPEndpoint(ctx context.Context) (kitNet.Addr, error) { */ func TestDisconnectAfterCredentialsUpdate(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate| - hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesCoapGateway| + hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() conn, err := grpc.NewClient(config.GRPC_GW_HOST, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ diff --git a/device-provisioning-service/service/provisionFail_test.go b/device-provisioning-service/service/provisionFail_test.go index f4c5c3ad6..0e12da207 100644 --- a/device-provisioning-service/service/provisionFail_test.go +++ b/device-provisioning-service/service/provisionFail_test.go @@ -102,8 +102,8 @@ func (h *testRequestHandlerWithExpiringCert) verify(ctx context.Context) error { func TestProvisioningWithExpiringCertificate(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() coapGWCfg := hubCoapGWTest.MakeConfig(t) @@ -253,8 +253,8 @@ func TestProvisioningWithExpiringCertificate(t *testing.T) { func TestProvisioningWithExpiredCertificate(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() coapGWCfg := hubCoapGWTest.MakeConfig(t) @@ -411,8 +411,9 @@ func (h *testRequestHandlerWithAuthCounter) verify(ctx context.Context) error { func TestProvisioningWithDeletedEnrollmentGroup(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesMachine2MachineOAuth| + hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate| + hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute) diff --git a/device-provisioning-service/service/provisionRecovery_test.go b/device-provisioning-service/service/provisionRecovery_test.go index 35307408d..6ea3ad0ac 100644 --- a/device-provisioning-service/service/provisionRecovery_test.go +++ b/device-provisioning-service/service/provisionRecovery_test.go @@ -40,8 +40,9 @@ type testDpsHandler interface { func testProvisioningWithDPSHandler(t *testing.T, h testDpsHandler, timeout time.Duration, onboardingOpts ...test.Option) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth| + hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate| + hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), timeout) diff --git a/device-provisioning-service/service/provisionRestart_test.go b/device-provisioning-service/service/provisionRestart_test.go index 61871dd1a..4ed4bf451 100644 --- a/device-provisioning-service/service/provisionRestart_test.go +++ b/device-provisioning-service/service/provisionRestart_test.go @@ -33,11 +33,13 @@ func TestReprovisioningAfterRestart(t *testing.T) { const expectedCloudConfigurationCount = failLimit + 1 const expectedCredentialsCount = failLimit + 1 const expectedACLsCount = failLimit + 1 - h := test.NewRequestHandlerWithExpectedCounters(t, failLimit, codes.InternalServerError, expectedTimeCount, expectedOwnershipCount, expectedCloudConfigurationCount, expectedCredentialsCount, expectedACLsCount) + h := test.NewRequestHandlerWithExpectedCounters(t, failLimit, codes.InternalServerError, expectedTimeCount, expectedOwnershipCount, + expectedCloudConfigurationCount, expectedCredentialsCount, expectedACLsCount) defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth| + hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate| + hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2) diff --git a/device-provisioning-service/service/provisionRetry_test.go b/device-provisioning-service/service/provisionRetry_test.go index c4cc0af9a..1f93ec5e7 100644 --- a/device-provisioning-service/service/provisionRetry_test.go +++ b/device-provisioning-service/service/provisionRetry_test.go @@ -90,8 +90,8 @@ func TestForceReprovisioning(t *testing.T) { dpsCfg := test.MakeConfig(t) rh := newTestRequestHandler(t, dpsCfg, defaultTestDpsHandlerConfig()) defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), time.Minute) diff --git a/device-provisioning-service/service/provision_test.go b/device-provisioning-service/service/provision_test.go index 63028947d..dd489f31f 100644 --- a/device-provisioning-service/service/provision_test.go +++ b/device-provisioning-service/service/provision_test.go @@ -48,8 +48,8 @@ const ( func TestProvisioning(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() err := test.SendSignalToDocker(test.TestDockerContainerName, "HUP") @@ -152,8 +152,8 @@ func TestProvisioning(t *testing.T) { func TestProvisioningFactoryReset(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesCoapGateway|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() conn, err := grpc.NewClient(config.GRPC_GW_HOST, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{ @@ -214,8 +214,8 @@ func TestProvisioningFactoryReset(t *testing.T) { } func TestProvisioningWithCloudChange(t *testing.T) { - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), time.Minute*2) @@ -319,8 +319,8 @@ func writeToTempFile(t *testing.T, fileName string, data []byte) string { } func TestProvisioningWithPSK(t *testing.T) { - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), time.Second*3600) @@ -400,8 +400,8 @@ func TestProvisioningWithPSK(t *testing.T) { } func TestProvisioningFromNewDPSAddress(t *testing.T) { - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId| - hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth| + hubTestService.SetUpServicesId|hubTestService.SetUpServicesResourceAggregate|hubTestService.SetUpServicesGrpcGateway) defer hubShutdown() ctx, cancel := context.WithTimeout(context.Background(), time.Second*30) diff --git a/device-provisioning-service/service/service.go b/device-provisioning-service/service/service.go index 977c2f465..8c6e6a228 100644 --- a/device-provisioning-service/service/service.go +++ b/device-provisioning-service/service/service.go @@ -196,8 +196,11 @@ func New(ctx context.Context, config Config, fileWatcher *fsnotify.Watcher, logg ss, err := s.createServices(fileWatcher, logger) if err != nil { + if httpService != nil { + httpService.Close() + } closer.Execute() - return nil, fmt.Errorf("cannot coap services: %w", err) + return nil, fmt.Errorf("cannot create coap services: %w", err) } if httpService != nil { ss.Add(httpService) diff --git a/device-provisioning-service/service/service_test.go b/device-provisioning-service/service/service_test.go index 75a219ad1..b21886cca 100644 --- a/device-provisioning-service/service/service_test.go +++ b/device-provisioning-service/service/service_test.go @@ -18,7 +18,8 @@ import ( func TestServiceServe(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory| + hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() log.Infof("%v\n\n", test.MakeConfig(t)) @@ -34,7 +35,8 @@ func TestServiceServe(t *testing.T) { func TestClientInactivity(t *testing.T) { defer test.ClearDB(t) - hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) + hubShutdown := hubTestService.SetUpServices(context.Background(), t, hubTestService.SetUpServicesCertificateAuthority|hubTestService.SetUpServicesResourceDirectory| + hubTestService.SetUpServicesMachine2MachineOAuth|hubTestService.SetUpServicesOAuth|hubTestService.SetUpServicesId) defer hubShutdown() dpsCfg := test.MakeConfig(t) dpsCfg.APIs.COAP.InactivityMonitor.Timeout = time.Second * 1