iotagent-node-lib 2.15.1 → 2.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +17 -1
- package/.readthedocs.yml +7 -0
- package/CHANGES_NEXT_RELEASE +0 -1
- package/README.md +1 -0
- package/doc/Contribution.md +60 -1
- package/doc/advanced-topics.md +136 -14
- package/doc/api.md +38 -22
- package/doc/apiary/iotagent.apib +1 -3
- package/doc/architecture.md +2 -2
- package/doc/config-basic-example.js +0 -1
- package/doc/deprecated.md +2 -2
- package/doc/development.md +13 -6
- package/doc/expressionLanguage.md +519 -277
- package/doc/getting-started.md +0 -1
- package/doc/howto.md +13 -17
- package/doc/installationguide.md +67 -69
- package/doc/usermanual.md +48 -16
- package/docker/Mosquitto/Dockerfile +4 -9
- package/docker/Mosquitto/README.md +2 -0
- package/docker/Mosquitto/startMosquitto.sh +18 -1
- package/lib/command/commandLine.js +1 -1
- package/lib/commonConfig.js +5 -14
- package/lib/errors.js +0 -16
- package/lib/fiware-iotagent-lib.js +5 -0
- package/lib/jexlTranformsMap.js +71 -0
- package/lib/model/Command.js +1 -1
- package/lib/model/Device.js +5 -2
- package/lib/model/Group.js +20 -2
- package/lib/model/dbConn.js +7 -1
- package/lib/plugins/attributeAlias.js +6 -13
- package/lib/plugins/bidirectionalData.js +2 -27
- package/lib/plugins/expressionParser.js +41 -17
- package/lib/plugins/expressionPlugin.js +21 -27
- package/lib/plugins/jexlParser.js +71 -67
- package/lib/plugins/multiEntity.js +68 -147
- package/lib/plugins/pluginUtils.js +12 -48
- package/lib/plugins/timestampProcessPlugin.js +1 -46
- package/lib/request-shim.js +111 -0
- package/lib/services/common/domain.js +2 -2
- package/lib/services/common/genericMiddleware.js +6 -2
- package/lib/services/common/iotManagerService.js +1 -1
- package/lib/services/common/securityServiceKeystone.js +1 -1
- package/lib/services/common/securityServiceOAuth2.js +3 -2
- package/lib/services/devices/deviceRegistryMongoDB.js +29 -22
- package/lib/services/devices/deviceService.js +56 -33
- package/lib/services/devices/devices-NGSI-LD.js +42 -14
- package/lib/services/devices/devices-NGSI-mixed.js +3 -3
- package/lib/services/devices/devices-NGSI-v2.js +48 -24
- package/lib/services/devices/registrationUtils.js +1 -134
- package/lib/services/groups/groupRegistryMemory.js +2 -0
- package/lib/services/groups/groupRegistryMongoDB.js +58 -76
- package/lib/services/groups/groupService.js +1 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +205 -124
- package/lib/services/ngsi/entities-NGSI-v2.js +142 -32
- package/lib/services/ngsi/ngsiService.js +4 -6
- package/lib/services/ngsi/ngsiUtils.js +0 -21
- package/lib/services/ngsi/subscription-NGSI-LD.js +14 -5
- package/lib/services/ngsi/subscriptionService.js +1 -4
- package/lib/services/northBound/contextServer-NGSI-LD.js +7 -2
- package/lib/services/northBound/contextServer-NGSI-v2.js +25 -13
- package/lib/services/northBound/contextServer.js +1 -4
- package/lib/services/northBound/contextServerUtils.js +0 -81
- package/lib/services/northBound/deviceProvisioningServer.js +36 -9
- package/lib/services/northBound/northboundServer.js +2 -0
- package/lib/services/northBound/restUtils.js +2 -39
- package/lib/templates/updateDevice.json +4 -0
- package/lib/templates/updateDeviceLax.json +4 -0
- package/package.json +13 -13
- package/test/tools/utils.js +2 -0
- package/test/unit/examples/deviceProvisioningRequests/provisionAnotherDevice.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionDeviceMissingParameters.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionDuplicatedDev.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -1
- package/test/unit/examples/deviceProvisioningRequests/provisionNewDeviceMalformed1.json +1 -1
- package/test/unit/examples/groupProvisioningRequests/multipleGroupsCreation.json +1 -1
- package/test/unit/examples/iotamRequests/registrationEmpty.json +1 -1
- package/test/unit/examples/iotamRequests/registrationWithGroups.json +2 -2
- package/test/unit/examples/iotamRequests/registrationWithGroupsWithoutCB.json +2 -2
- package/test/unit/examples/iotamRequests/registrationWithStaticGroups.json +2 -2
- package/test/unit/expressions/jexlExpression-test.js +119 -0
- package/test/unit/general/config-multi-core-test.js +1 -1
- package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +30 -77
- package/test/unit/general/deviceService-test.js +19 -35
- package/test/unit/general/loglevel-api_test.js +8 -13
- package/test/unit/general/migration-test.js +1 -0
- package/test/unit/general/startup-test.js +3 -2
- package/test/unit/general/statistics-persistence_test.js +2 -2
- package/test/unit/general/statistics-service_test.js +2 -2
- package/test/unit/lazyAndCommands/commandRegistry_test.js +18 -18
- package/test/unit/memoryRegistry/deviceRegistryMemory_test.js +16 -24
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -2
- package/test/unit/mongodb/mongodb-group-registry-test.js +11 -11
- package/test/unit/mongodb/mongodb-registry-test.js +55 -131
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent1.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgent4.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateCommands1.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent1.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent2.json +1 -1
- package/test/unit/ngsi-ld/examples/contextAvailabilityRequests/updateIoTAgent3.json +1 -1
- package/test/unit/ngsi-ld/examples/contextRequests/createMinimumProvisionedDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -14
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -14
- package/test/unit/ngsi-ld/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic3.json +1 -15
- package/test/unit/ngsi-ld/examples/contextRequests/createTimeInstantMinimumDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAliasPlugin6.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextAutocast5.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin12a.json +7 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin13.json +13 -13
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin16.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin17.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin31.json +15 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +17 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin33.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin34.json +17 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin4a.json +36 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin5.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin7.json +16 -16
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin8a.json +18 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextGeoproperties3.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +6 -6
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +3 -3
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionCommands1.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionDeviceStatic.json +0 -7
- package/test/unit/ngsi-ld/examples/contextRequests/updateProvisionMinimumDevice.json +0 -7
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +20 -17
- package/test/unit/ngsi-ld/examples/subscriptionRequests/simpleSubscriptionRequest.json +18 -15
- package/test/unit/ngsi-ld/examples/subscriptionRequests/simpleSubscriptionRequest2.json +18 -15
- package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +21 -21
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +1018 -0
- package/test/unit/ngsi-ld/general/config-jsonld-contexts-test.js +2 -2
- package/test/unit/ngsi-ld/general/contextBrokerOAuthSecurityAccess-test.js +24 -24
- package/test/unit/ngsi-ld/general/deviceService-test.js +7 -7
- package/test/unit/ngsi-ld/general/https-support-test.js +14 -13
- package/test/unit/ngsi-ld/general/iotam-autoregistration-test.js +8 -7
- package/test/unit/ngsi-ld/general/startup-test.js +2 -1
- package/test/unit/ngsi-ld/lazyAndCommands/active-devices-attribute-update-test.js +10 -8
- package/test/unit/ngsi-ld/lazyAndCommands/command-test.js +11 -12
- package/test/unit/ngsi-ld/lazyAndCommands/lazy-devices-test.js +25 -29
- package/test/unit/ngsi-ld/lazyAndCommands/polling-commands-test.js +16 -15
- package/test/unit/ngsi-ld/ngsiService/active-devices-test.js +18 -17
- package/test/unit/ngsi-ld/ngsiService/autocast-test.js +13 -12
- package/test/unit/ngsi-ld/ngsiService/geoproperties-test.js +10 -9
- package/test/unit/ngsi-ld/ngsiService/staticAttributes-test.js +3 -3
- package/test/unit/ngsi-ld/ngsiService/subscriptions-test.js +25 -24
- package/test/unit/ngsi-ld/plugins/alias-plugin_test.js +13 -12
- package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +27 -26
- package/test/unit/ngsi-ld/plugins/compress-timestamp-plugin_test.js +5 -5
- package/test/unit/ngsi-ld/plugins/event-plugin_test.js +3 -3
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +75 -14
- package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +3 -3
- package/test/unit/ngsi-ld/provisioning/device-provisioning-api_test.js +54 -53
- package/test/unit/ngsi-ld/provisioning/device-registration_test.js +20 -19
- package/test/unit/ngsi-ld/provisioning/device-update-registration_test.js +23 -22
- package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +58 -70
- package/test/unit/ngsi-ld/provisioning/provisionDeviceMultientity-test.js +8 -7
- package/test/unit/ngsi-ld/provisioning/removeProvisionedDevice-test.js +19 -19
- package/test/unit/ngsi-ld/provisioning/singleConfigurationMode-test.js +18 -20
- package/test/unit/ngsi-ld/provisioning/updateProvisionedDevices-test.js +43 -49
- package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +16 -14
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent1.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent3.json +19 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent4.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgent5.json +19 -0
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDevice.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup3.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateCommands1.json +3 -3
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent1.json +3 -3
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent2.json +1 -1
- package/test/unit/ngsiv2/examples/contextAvailabilityRequests/updateIoTAgent3.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +17 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin15.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin16.json +14 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin17.json +14 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin18.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin19.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +13 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin20.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin21.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin22.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin23.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin24.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin25.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin26.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin27.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin28.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +22 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +6 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +18 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +16 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +22 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +12 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +12 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +17 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +5 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware1.json +10 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMiddleware2.json +10 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +13 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +33 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +33 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +33 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +25 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +25 -0
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +8 -8
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +4 -4
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
- package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -2
- package/test/unit/ngsiv2/examples/contextRequests/updateProvisionDevice.json +20 -0
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +1 -1
- package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest.json +1 -1
- package/test/unit/ngsiv2/examples/subscriptionRequests/simpleSubscriptionRequest2.json +1 -1
- package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +93 -60
- package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +16 -16
- package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +548 -164
- package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +34 -33
- package/test/unit/ngsiv2/general/deviceService-test.js +15 -14
- package/test/unit/ngsiv2/general/https-support-test.js +14 -13
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +8 -7
- package/test/unit/ngsiv2/general/startup-test.js +2 -1
- package/test/unit/ngsiv2/lazyAndCommands/active-devices-attribute-update-test.js +9 -7
- package/test/unit/ngsiv2/lazyAndCommands/command-test.js +13 -12
- package/test/unit/ngsiv2/lazyAndCommands/lazy-devices-test.js +323 -51
- package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +22 -20
- package/test/unit/ngsiv2/ngsiService/active-devices-test.js +114 -26
- package/test/unit/ngsiv2/ngsiService/autocast-test.js +16 -16
- package/test/unit/ngsiv2/ngsiService/geoproperties-test.js +39 -38
- package/test/unit/{ngsiService → ngsiv2/ngsiService}/queryDeviceInformationInCb-test.js +25 -54
- package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +5 -5
- package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +25 -24
- package/test/unit/ngsiv2/plugins/alias-plugin_test.js +22 -22
- package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +27 -26
- package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +7 -7
- package/test/unit/ngsiv2/plugins/event-plugin_test.js +4 -4
- package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +549 -24
- package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +4 -4
- package/test/unit/{plugins → ngsiv2/plugins}/translation-inPlugins_test.js +25 -25
- package/test/unit/{provisioning → ngsiv2/provisioning}/device-group-api-test.js +44 -75
- package/test/unit/{provisioning/device-group-utils_test.js → ngsiv2/provisioning/device-group-utils-test.js} +15 -14
- package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +74 -73
- package/test/unit/ngsiv2/provisioning/device-registration_test.js +20 -19
- package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +30 -29
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +58 -69
- package/test/unit/ngsiv2/provisioning/provisionDeviceMultientity-test.js +8 -7
- package/test/unit/ngsiv2/provisioning/removeProvisionedDevice-test.js +19 -19
- package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +18 -19
- package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +49 -52
- package/test/unit/plugins/capture-configuration-inPlugins_test.js +6 -4
- package/test/unit/plugins/capture-provision-inPlugins_test.js +13 -23
- package/.nyc_output/016aca19-69bf-4681-9b41-2835c5131681.json +0 -1
- package/.nyc_output/processinfo/016aca19-69bf-4681-9b41-2835c5131681.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/lib/services/devices/devices-NGSI-v1.js +0 -293
- package/lib/services/devices/registrationUtils.js_avega +0 -589
- package/lib/services/ngsi/entities-NGSI-v1.js +0 -300
- package/lib/services/ngsi/subscription-NGSI-v1.js +0 -234
- package/lib/services/northBound/contextServer-NGSI-v1.js +0 -526
- package/lib/templates/notificationTemplateNgsi1.json +0 -75
- package/lib/templates/updateContextNgsi1.json +0 -50
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent2.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent3.json +0 -25
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgent4.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentAttributeUpdates.json +0 -16
- package/test/unit/examples/contextAvailabilityRequests/registerIoTAgentCommands.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerNewDevice2.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice.json +0 -25
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDevice2.json +0 -21
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup.json +0 -33
- package/test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json +0 -33
- package/test/unit/examples/contextAvailabilityRequests/unregisterDevice1.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/unregisterDevice3.json +0 -26
- package/test/unit/examples/contextAvailabilityRequests/unregisterProvisionedDevice.json +0 -26
- package/test/unit/examples/contextAvailabilityRequests/updateCommands1.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent1.json +0 -22
- package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent2.json +0 -26
- package/test/unit/examples/contextAvailabilityRequests/updateIoTAgent3.json +0 -22
- package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Failed.json +0 -8
- package/test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/registerNewDevice2Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Failed.json +0 -8
- package/test/unit/examples/contextAvailabilityResponses/unregisterDevice1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/updateCommands1Success.json +0 -4
- package/test/unit/examples/contextAvailabilityResponses/updateIoTAgent1Success.json +0 -6
- package/test/unit/examples/contextProviderResponses/queryInformationResponse.json +0 -22
- package/test/unit/examples/contextProviderResponses/queryInformationResponseEmptyAttributes.json +0 -22
- package/test/unit/examples/contextProviderResponses/queryInformationStaticAttributesResponse.json +0 -27
- package/test/unit/examples/contextProviderResponses/updateInformationResponse.json +0 -22
- package/test/unit/examples/contextProviderResponses/updateInformationResponse2.json +0 -22
- package/test/unit/examples/contextRequests/contextSubscriptionRequest.json +0 -20
- package/test/unit/examples/contextRequests/contextSubscriptionRequest2.json +0 -20
- package/test/unit/examples/contextRequests/createBidirectionalDevice.json +0 -17
- package/test/unit/examples/contextRequests/createDatetimeProvisionedDevice.json +0 -17
- package/test/unit/examples/contextRequests/createGeopointProvisionedDevice.json +0 -17
- package/test/unit/examples/contextRequests/createMinimumProvisionedDevice.json +0 -17
- package/test/unit/examples/contextRequests/createProvisionedDevice.json +0 -32
- package/test/unit/examples/contextRequests/createProvisionedDeviceMultientity.json +0 -32
- package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroup.json +0 -47
- package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic.json +0 -52
- package/test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json +0 -52
- package/test/unit/examples/contextRequests/createTimeinstantDevice.json +0 -17
- package/test/unit/examples/contextRequests/queryContext1.json +0 -13
- package/test/unit/examples/contextRequests/queryContext2.json +0 -13
- package/test/unit/examples/contextRequests/queryContextAliasPlugin1.json +0 -10
- package/test/unit/examples/contextRequests/queryContextCompressTimestamp1.json +0 -13
- package/test/unit/examples/contextRequests/updateActiveAttributes.json +0 -11
- package/test/unit/examples/contextRequests/updateContext1.json +0 -22
- package/test/unit/examples/contextRequests/updateContext2.json +0 -22
- package/test/unit/examples/contextRequests/updateContext3.json +0 -17
- package/test/unit/examples/contextRequests/updateContext3WithStatic.json +0 -22
- package/test/unit/examples/contextRequests/updateContext4.json +0 -22
- package/test/unit/examples/contextRequests/updateContext5.json +0 -19
- package/test/unit/examples/contextRequests/updateContextAliasPlugin.json +0 -22
- package/test/unit/examples/contextRequests/updateContextAliasPlugin2.json +0 -17
- package/test/unit/examples/contextRequests/updateContextAppendMode.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandError.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandExpired.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandFinish.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCommandStatus.json +0 -17
- package/test/unit/examples/contextRequests/updateContextCompressTimestamp1.json +0 -22
- package/test/unit/examples/contextRequests/updateContextCompressTimestamp2.json +0 -29
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin1.json +0 -17
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin2.json +0 -27
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin3.json +0 -17
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin4.json +0 -17
- package/test/unit/examples/contextRequests/updateContextExpressionPlugin5.json +0 -27
- package/test/unit/examples/contextRequests/updateContextMiddleware1.json +0 -22
- package/test/unit/examples/contextRequests/updateContextMultiEntityPlugin3.json +0 -35
- package/test/unit/examples/contextRequests/updateContextMultientityPlugin1.json +0 -30
- package/test/unit/examples/contextRequests/updateContextMultientityPlugin2.json +0 -30
- package/test/unit/examples/contextRequests/updateContextProcessTimestamp1.json +0 -29
- package/test/unit/examples/contextRequests/updateContextStaticAttributes.json +0 -22
- package/test/unit/examples/contextRequests/updateContextTimestamp.json +0 -41
- package/test/unit/examples/contextRequests/updateContextTimestampOverride.json +0 -22
- package/test/unit/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +0 -22
- package/test/unit/examples/contextRequests/updateContextTimestampTimezone.json +0 -41
- package/test/unit/examples/contextRequests/updateProvisionActiveAttributes1.json +0 -17
- package/test/unit/examples/contextRequests/updateProvisionCommands1.json +0 -27
- package/test/unit/examples/contextRequests/updateProvisionDeviceStatic.json +0 -38
- package/test/unit/examples/contextRequests/updateProvisionMinimumDevice.json +0 -17
- package/test/unit/examples/contextResponses/contextSubscriptionRequest2Success.json +0 -7
- package/test/unit/examples/contextResponses/contextSubscriptionRequestSuccess.json +0 -7
- package/test/unit/examples/contextResponses/createBidirectionalDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createDatetimeProvisionedDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createGeopointProvisionedDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json +0 -22
- package/test/unit/examples/contextResponses/createTimeinstantSuccess.json +0 -22
- package/test/unit/examples/contextResponses/queryContext1Success.json +0 -27
- package/test/unit/examples/contextResponses/queryContext2Error.json +0 -7
- package/test/unit/examples/contextResponses/queryContext2UnknownError.json +0 -6
- package/test/unit/examples/contextResponses/queryContext3Error.json +0 -34
- package/test/unit/examples/contextResponses/queryContextAliasPlugin1Success.json +0 -27
- package/test/unit/examples/contextResponses/queryContextCompressTimestamp1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateActiveAttributesSuccess.json +0 -16
- package/test/unit/examples/contextResponses/updateContext1Failed.json +0 -7
- package/test/unit/examples/contextResponses/updateContext1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContext2Failed.json +0 -35
- package/test/unit/examples/contextResponses/updateContextAliasPlugin2Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContextAliasPluginSuccess.json +0 -27
- package/test/unit/examples/contextResponses/updateContextCommandFinishSuccess.json +0 -27
- package/test/unit/examples/contextResponses/updateContextCommandStatusSuccess.json +0 -22
- package/test/unit/examples/contextResponses/updateContextCompressTimestamp1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContextCompressTimestamp2Success.json +0 -34
- package/test/unit/examples/contextResponses/updateContextEvents1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin1Success.json +0 -22
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin2Success.json +0 -22
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin3Success.json +0 -22
- package/test/unit/examples/contextResponses/updateContextExpressionPlugin5Success.json +0 -32
- package/test/unit/examples/contextResponses/updateContextMultientityPlugin1Success.json +0 -40
- package/test/unit/examples/contextResponses/updateContextMultientityPlugin2Success.json +0 -40
- package/test/unit/examples/contextResponses/updateContextMultientityPlugin3Success.json +0 -40
- package/test/unit/examples/contextResponses/updateContextProcessTimestamp1Success.json +0 -27
- package/test/unit/examples/contextResponses/updateProvisionActiveAttributes1Success.json +0 -22
- package/test/unit/examples/contextResponses/updateProvisionCommands1Success.json +0 -32
- package/test/unit/examples/contextResponses/updateProvisionMinimumDeviceSuccess.json +0 -22
- package/test/unit/examples/subscriptionRequests/bidirectionalNotification.json +0 -24
- package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRemove.json +0 -3
- package/test/unit/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -22
- package/test/unit/examples/subscriptionRequests/errorNotification.json +0 -24
- package/test/unit/examples/subscriptionRequests/simpleNotification.json +0 -24
- package/test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json +0 -3
- package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json +0 -19
- package/test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json +0 -19
- package/test/unit/examples/subscriptionResponses/bidirectionalSubscriptionSuccess.json +0 -6
- package/test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json +0 -6
- package/test/unit/expressions/expressionBasedTransformations-test.js +0 -328
- package/test/unit/expressions/expressionCombinedTransformations-test.js +0 -306
- package/test/unit/expressions/jexlBasedTransformations-test.js +0 -334
- package/test/unit/general/contextBrokerOAuthSecurityAccess-test.js +0 -902
- package/test/unit/general/https-support-test.js +0 -286
- package/test/unit/general/iotam-autoregistration-test.js +0 -368
- package/test/unit/lazyAndCommands/active-devices-attribute-update-test.js +0 -168
- package/test/unit/lazyAndCommands/command-test.js +0 -341
- package/test/unit/lazyAndCommands/lazy-devices-test.js +0 -878
- package/test/unit/lazyAndCommands/polling-commands-test.js +0 -421
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin20.json +0 -25
- package/test/unit/ngsiService/active-devices-test.js +0 -692
- package/test/unit/ngsiService/staticAttributes-test.js +0 -148
- package/test/unit/ngsiService/subscriptions-test.js +0 -345
- package/test/unit/plugins/alias-plugin_test.js +0 -158
- package/test/unit/plugins/bidirectional-plugin_test.js +0 -564
- package/test/unit/plugins/compress-timestamp-plugin_test.js +0 -257
- package/test/unit/plugins/event-plugin_test.js +0 -119
- package/test/unit/plugins/multientity-plugin_test.js +0 -248
- package/test/unit/plugins/timestamp-processing-plugin_test.js +0 -119
- package/test/unit/provisioning/device-provisioning-api_test.js +0 -748
- package/test/unit/provisioning/device-registration_test.js +0 -432
- package/test/unit/provisioning/device-update-registration_test.js +0 -326
- package/test/unit/provisioning/listProvisionedDevices-test.js +0 -488
- package/test/unit/provisioning/provisionDeviceMultientity-test.js +0 -123
- package/test/unit/provisioning/removeProvisionedDevice-test.js +0 -244
- package/test/unit/provisioning/singleConfigurationMode-test.js +0 -346
- package/test/unit/provisioning/updateProvisionedDevices-test.js +0 -436
|
@@ -1,902 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
|
|
3
|
-
*
|
|
4
|
-
* This file is part of fiware-iotagent-lib
|
|
5
|
-
*
|
|
6
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
7
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
8
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
9
|
-
* or (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
14
|
-
* See the GNU Affero General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU Affero General Public
|
|
17
|
-
* License along with fiware-iotagent-lib.
|
|
18
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
19
|
-
*
|
|
20
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
21
|
-
* please contact with::[contacto@tid.es]
|
|
22
|
-
*
|
|
23
|
-
* Modified by: Daniel Calvo - ATOS Research & Innovation
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* eslint-disable no-unused-vars */
|
|
27
|
-
|
|
28
|
-
const iotAgentLib = require('../../../lib/fiware-iotagent-lib');
|
|
29
|
-
const utils = require('../../tools/utils');
|
|
30
|
-
const should = require('should');
|
|
31
|
-
const logger = require('logops');
|
|
32
|
-
const nock = require('nock');
|
|
33
|
-
const request = require('request');
|
|
34
|
-
let contextBrokerMock;
|
|
35
|
-
let oauth2Mock;
|
|
36
|
-
const iotAgentConfig = {
|
|
37
|
-
contextBroker: {
|
|
38
|
-
host: '192.168.1.1',
|
|
39
|
-
port: '1026'
|
|
40
|
-
},
|
|
41
|
-
server: {
|
|
42
|
-
port: 4041
|
|
43
|
-
},
|
|
44
|
-
authentication: {
|
|
45
|
-
type: 'oauth2',
|
|
46
|
-
url: 'http://192.168.1.1:3000',
|
|
47
|
-
header: 'Authorization',
|
|
48
|
-
clientId: 'context-broker',
|
|
49
|
-
clientSecret: 'c8d58d16-0a42-400e-9765-f32e154a5a9e',
|
|
50
|
-
tokenPath: '/auth/realms/default/protocol/openid-connect/token',
|
|
51
|
-
enabled: true
|
|
52
|
-
},
|
|
53
|
-
types: {
|
|
54
|
-
Light: {
|
|
55
|
-
service: 'smartGondor',
|
|
56
|
-
subservice: 'electricity',
|
|
57
|
-
trust: 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3',
|
|
58
|
-
type: 'Light',
|
|
59
|
-
commands: [],
|
|
60
|
-
lazy: [
|
|
61
|
-
{
|
|
62
|
-
name: 'temperature',
|
|
63
|
-
type: 'centigrades'
|
|
64
|
-
}
|
|
65
|
-
],
|
|
66
|
-
active: [
|
|
67
|
-
{
|
|
68
|
-
name: 'pressure',
|
|
69
|
-
type: 'Hgmm'
|
|
70
|
-
}
|
|
71
|
-
]
|
|
72
|
-
},
|
|
73
|
-
Termometer: {
|
|
74
|
-
commands: [],
|
|
75
|
-
type: 'Termometer',
|
|
76
|
-
lazy: [
|
|
77
|
-
{
|
|
78
|
-
name: 'temp',
|
|
79
|
-
type: 'kelvin'
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
active: []
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
service: 'smartGondor',
|
|
86
|
-
subservice: 'gardens',
|
|
87
|
-
providerUrl: 'http://smartGondor.com',
|
|
88
|
-
deviceRegistrationDuration: 'P1M'
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
describe('NGSI-v1 - Secured access to the Context Broker with OAuth2 provider', function () {
|
|
92
|
-
const values = [
|
|
93
|
-
{
|
|
94
|
-
name: 'state',
|
|
95
|
-
type: 'Boolean',
|
|
96
|
-
value: 'true'
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
name: 'dimming',
|
|
100
|
-
type: 'Percentage',
|
|
101
|
-
value: '87'
|
|
102
|
-
}
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
beforeEach(function () {
|
|
106
|
-
logger.setLevel('FATAL');
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
afterEach(function (done) {
|
|
110
|
-
iotAgentLib.deactivate(done);
|
|
111
|
-
nock.cleanAll();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('When a measure is sent to the Context Broker via an Update Context operation', function () {
|
|
115
|
-
beforeEach(function (done) {
|
|
116
|
-
nock.cleanAll();
|
|
117
|
-
|
|
118
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
119
|
-
.post(
|
|
120
|
-
'/auth/realms/default/protocol/openid-connect/token',
|
|
121
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
122
|
-
)
|
|
123
|
-
.reply(201, utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrust.json'), {});
|
|
124
|
-
|
|
125
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
126
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
127
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
128
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
129
|
-
.post(
|
|
130
|
-
'/v1/updateContext',
|
|
131
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext1.json')
|
|
132
|
-
)
|
|
133
|
-
.reply(200, utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json'));
|
|
134
|
-
|
|
135
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should ask OAuth2 provider for a token based on the trust token', function (done) {
|
|
139
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
140
|
-
should.not.exist(error);
|
|
141
|
-
oauth2Mock.done();
|
|
142
|
-
done();
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
it('should send the generated token in the auth header', function (done) {
|
|
146
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
147
|
-
should.not.exist(error);
|
|
148
|
-
contextBrokerMock.done();
|
|
149
|
-
done();
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
describe('When a measure is sent to the Context Broker and the access is forbidden', function () {
|
|
154
|
-
beforeEach(function (done) {
|
|
155
|
-
nock.cleanAll();
|
|
156
|
-
|
|
157
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
158
|
-
.post(
|
|
159
|
-
'/auth/realms/default/protocol/openid-connect/token',
|
|
160
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
161
|
-
)
|
|
162
|
-
.reply(201, utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrust.json'), {});
|
|
163
|
-
|
|
164
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
165
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
166
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
167
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
168
|
-
.post(
|
|
169
|
-
'/v1/updateContext',
|
|
170
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext1.json')
|
|
171
|
-
)
|
|
172
|
-
.reply(403, utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json'));
|
|
173
|
-
|
|
174
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('it should return a ACCESS_FORBIDDEN error to the caller', function (done) {
|
|
178
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
179
|
-
should.exist(error);
|
|
180
|
-
error.name.should.equal('ACCESS_FORBIDDEN');
|
|
181
|
-
done();
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
describe('When a measure is sent and the trust is rejected asking for the token', function () {
|
|
186
|
-
beforeEach(function (done) {
|
|
187
|
-
nock.cleanAll();
|
|
188
|
-
|
|
189
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
190
|
-
.post(
|
|
191
|
-
'/auth/realms/default/protocol/openid-connect/token',
|
|
192
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
193
|
-
)
|
|
194
|
-
.reply(
|
|
195
|
-
400,
|
|
196
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustUnauthorized.json')
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
200
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
201
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
202
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
203
|
-
.post(
|
|
204
|
-
'/v1/updateContext',
|
|
205
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext1.json')
|
|
206
|
-
)
|
|
207
|
-
.reply(200, utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json'));
|
|
208
|
-
|
|
209
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('it should return a AUTHENTICATION_ERROR error to the caller', function (done) {
|
|
213
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
214
|
-
should.exist(error);
|
|
215
|
-
error.name.should.equal('AUTHENTICATION_ERROR');
|
|
216
|
-
done();
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
describe('When the user requests information about a device in a protected CB', function () {
|
|
222
|
-
const attributes = ['state', 'dimming'];
|
|
223
|
-
|
|
224
|
-
beforeEach(function (done) {
|
|
225
|
-
nock.cleanAll();
|
|
226
|
-
|
|
227
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
228
|
-
.post(
|
|
229
|
-
'/auth/realms/default/protocol/openid-connect/token',
|
|
230
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
231
|
-
)
|
|
232
|
-
.reply(201, utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrust.json'), {});
|
|
233
|
-
|
|
234
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
235
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
236
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
237
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
238
|
-
.post(
|
|
239
|
-
'/v1/queryContext',
|
|
240
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/queryContext1.json')
|
|
241
|
-
)
|
|
242
|
-
.reply(200, utils.readExampleFile('./test/unit/examples/contextResponses/queryContext1Success.json'));
|
|
243
|
-
|
|
244
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('should send the Auth Token along with the information query', function (done) {
|
|
248
|
-
iotAgentLib.query('light1', 'Light', '', attributes, function (error) {
|
|
249
|
-
should.not.exist(error);
|
|
250
|
-
contextBrokerMock.done();
|
|
251
|
-
done();
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
describe('When subscriptions are used on a protected Context Broker', function () {
|
|
257
|
-
beforeEach(function (done) {
|
|
258
|
-
const optionsProvision = {
|
|
259
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
260
|
-
method: 'POST',
|
|
261
|
-
json: utils.readExampleFile(
|
|
262
|
-
'./test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice3.json'
|
|
263
|
-
),
|
|
264
|
-
headers: {
|
|
265
|
-
'fiware-service': 'smartGondor',
|
|
266
|
-
'fiware-servicepath': 'electricity'
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
|
|
270
|
-
nock.cleanAll();
|
|
271
|
-
|
|
272
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
273
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
274
|
-
.post(
|
|
275
|
-
'/auth/realms/default/protocol/openid-connect/token',
|
|
276
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
277
|
-
)
|
|
278
|
-
.times(3)
|
|
279
|
-
.reply(201, utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrust.json'), {});
|
|
280
|
-
|
|
281
|
-
contextBrokerMock = nock('http://192.168.1.1:1026');
|
|
282
|
-
|
|
283
|
-
contextBrokerMock
|
|
284
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
285
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
286
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
287
|
-
.post(
|
|
288
|
-
'/v1/updateContext',
|
|
289
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext5.json')
|
|
290
|
-
)
|
|
291
|
-
.reply(
|
|
292
|
-
200,
|
|
293
|
-
utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json')
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
contextBrokerMock
|
|
297
|
-
.post(
|
|
298
|
-
'/NGSI9/registerContext',
|
|
299
|
-
utils.readExampleFile(
|
|
300
|
-
'./test/unit/examples/contextAvailabilityRequests/registerNewDevice1.json'
|
|
301
|
-
)
|
|
302
|
-
)
|
|
303
|
-
.reply(
|
|
304
|
-
200,
|
|
305
|
-
utils.readExampleFile(
|
|
306
|
-
'./test/unit/examples/contextAvailabilityResponses/registerNewDevice1Success.json'
|
|
307
|
-
)
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
contextBrokerMock
|
|
311
|
-
.post(
|
|
312
|
-
'/v1/subscribeContext',
|
|
313
|
-
utils.readExampleFile(
|
|
314
|
-
'./test/unit/examples/subscriptionRequests/simpleSubscriptionRequest1.json'
|
|
315
|
-
)
|
|
316
|
-
)
|
|
317
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
318
|
-
.reply(
|
|
319
|
-
200,
|
|
320
|
-
utils.readExampleFile(
|
|
321
|
-
'./test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json'
|
|
322
|
-
)
|
|
323
|
-
);
|
|
324
|
-
|
|
325
|
-
iotAgentLib.clearAll(function () {
|
|
326
|
-
request(optionsProvision, function (error, result, body) {
|
|
327
|
-
done();
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it('subscribe requests use auth header', function (done) {
|
|
334
|
-
iotAgentLib.getDevice('Light1', 'smartGondor', 'electricity', function (error, device) {
|
|
335
|
-
iotAgentLib.subscribe(device, ['dimming'], null, function (error) {
|
|
336
|
-
should.not.exist(error);
|
|
337
|
-
|
|
338
|
-
contextBrokerMock.done();
|
|
339
|
-
|
|
340
|
-
done();
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
it('unsubscribe requests use auth header', function (done) {
|
|
346
|
-
oauth2Mock
|
|
347
|
-
.post(
|
|
348
|
-
'/auth/realms/default/protocol/openid-connect/token',
|
|
349
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
350
|
-
)
|
|
351
|
-
.reply(201, utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrust.json'), {});
|
|
352
|
-
|
|
353
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
354
|
-
.post(
|
|
355
|
-
'/v1/unsubscribeContext',
|
|
356
|
-
utils.readExampleFile('./test/unit/examples/subscriptionRequests/simpleSubscriptionRemove.json')
|
|
357
|
-
)
|
|
358
|
-
.matchHeader('Authorization', 'Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ3cHdWclJ3')
|
|
359
|
-
.reply(
|
|
360
|
-
200,
|
|
361
|
-
utils.readExampleFile('./test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json')
|
|
362
|
-
);
|
|
363
|
-
|
|
364
|
-
iotAgentLib.getDevice('Light1', 'smartGondor', 'electricity', function (error, device) {
|
|
365
|
-
iotAgentLib.subscribe(device, ['dimming'], null, function (error) {
|
|
366
|
-
iotAgentLib.unsubscribe(device, '51c0ac9ed714fb3b37d7d5a8', function (error) {
|
|
367
|
-
contextBrokerMock.done();
|
|
368
|
-
done();
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
|
|
376
|
-
describe('Secured access to the Context Broker with OAuth2 provider (FIWARE Keyrock IDM)', function () {
|
|
377
|
-
const values = [
|
|
378
|
-
{
|
|
379
|
-
name: 'state',
|
|
380
|
-
type: 'Boolean',
|
|
381
|
-
value: 'true'
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
name: 'dimming',
|
|
385
|
-
type: 'Percentage',
|
|
386
|
-
value: '87'
|
|
387
|
-
}
|
|
388
|
-
];
|
|
389
|
-
|
|
390
|
-
beforeEach(function () {
|
|
391
|
-
logger.setLevel('FATAL');
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
afterEach(function (done) {
|
|
395
|
-
iotAgentLib.deactivate(done);
|
|
396
|
-
nock.cleanAll();
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
describe('When a measure is sent to the Context Broker via an Update Context operation', function () {
|
|
400
|
-
beforeEach(function (done) {
|
|
401
|
-
nock.cleanAll();
|
|
402
|
-
|
|
403
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
404
|
-
.post(
|
|
405
|
-
'/oauth2/token',
|
|
406
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
407
|
-
)
|
|
408
|
-
.reply(
|
|
409
|
-
200,
|
|
410
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock.json'),
|
|
411
|
-
{}
|
|
412
|
-
);
|
|
413
|
-
|
|
414
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
415
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
416
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
417
|
-
.matchHeader('Authorization', 'Bearer c1b752e377680acd1349a3ed59db855a1db07605')
|
|
418
|
-
.post(
|
|
419
|
-
'/v1/updateContext',
|
|
420
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext1.json')
|
|
421
|
-
)
|
|
422
|
-
.reply(200, utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json'));
|
|
423
|
-
|
|
424
|
-
iotAgentConfig.authentication.tokenPath = '/oauth2/token';
|
|
425
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
it('should ask OAuth2 provider for a token based on the trust token', function (done) {
|
|
429
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
430
|
-
should.not.exist(error);
|
|
431
|
-
oauth2Mock.done();
|
|
432
|
-
done();
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
it('should send the generated token in the auth header', function (done) {
|
|
436
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
437
|
-
should.not.exist(error);
|
|
438
|
-
contextBrokerMock.done();
|
|
439
|
-
done();
|
|
440
|
-
});
|
|
441
|
-
});
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
describe('When the user requests information about a device in a protected CB', function () {
|
|
445
|
-
const attributes = ['state', 'dimming'];
|
|
446
|
-
|
|
447
|
-
beforeEach(function (done) {
|
|
448
|
-
nock.cleanAll();
|
|
449
|
-
|
|
450
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
451
|
-
.post(
|
|
452
|
-
'/oauth2/token',
|
|
453
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
454
|
-
)
|
|
455
|
-
.reply(
|
|
456
|
-
200,
|
|
457
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock.json'),
|
|
458
|
-
{}
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
462
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
463
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
464
|
-
.matchHeader('Authorization', 'Bearer c1b752e377680acd1349a3ed59db855a1db07605')
|
|
465
|
-
.post(
|
|
466
|
-
'/v1/queryContext',
|
|
467
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/queryContext1.json')
|
|
468
|
-
)
|
|
469
|
-
.reply(200, utils.readExampleFile('./test/unit/examples/contextResponses/queryContext1Success.json'));
|
|
470
|
-
|
|
471
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
it('should send the Auth Token along with the information query', function (done) {
|
|
475
|
-
iotAgentLib.query('light1', 'Light', '', attributes, function (error) {
|
|
476
|
-
should.not.exist(error);
|
|
477
|
-
contextBrokerMock.done();
|
|
478
|
-
done();
|
|
479
|
-
});
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
|
|
483
|
-
describe('When a measure is sent and the refresh token is not valid', function () {
|
|
484
|
-
beforeEach(function (done) {
|
|
485
|
-
nock.cleanAll();
|
|
486
|
-
|
|
487
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
488
|
-
.post(
|
|
489
|
-
'/oauth2/token',
|
|
490
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
491
|
-
)
|
|
492
|
-
.reply(
|
|
493
|
-
400,
|
|
494
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustUnauthorizedKeyrock.json')
|
|
495
|
-
);
|
|
496
|
-
|
|
497
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('it should return a AUTHENTICATION_ERROR error to the caller', function (done) {
|
|
501
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
502
|
-
should.exist(error);
|
|
503
|
-
error.name.should.equal('AUTHENTICATION_ERROR');
|
|
504
|
-
done();
|
|
505
|
-
});
|
|
506
|
-
});
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
describe('When a measure is sent to the Context Broker and the client credentials are invalid', function () {
|
|
510
|
-
beforeEach(function (done) {
|
|
511
|
-
nock.cleanAll();
|
|
512
|
-
|
|
513
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
514
|
-
.post(
|
|
515
|
-
'/oauth2/token',
|
|
516
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
517
|
-
)
|
|
518
|
-
.reply(
|
|
519
|
-
400,
|
|
520
|
-
utils.readExampleFile(
|
|
521
|
-
'./test/unit/examples/oauthResponses/tokenFromTrustInvalidCredentialsKeyrock.json'
|
|
522
|
-
),
|
|
523
|
-
{}
|
|
524
|
-
);
|
|
525
|
-
|
|
526
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
527
|
-
});
|
|
528
|
-
|
|
529
|
-
it('it should return a AUTHENTICATION_ERROR error to the caller', function (done) {
|
|
530
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
531
|
-
should.exist(error);
|
|
532
|
-
error.name.should.equal('AUTHENTICATION_ERROR');
|
|
533
|
-
done();
|
|
534
|
-
});
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
describe('When a measure is sent to the Context Broker and the access is unauthorized', function () {
|
|
539
|
-
beforeEach(function (done) {
|
|
540
|
-
nock.cleanAll();
|
|
541
|
-
|
|
542
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
543
|
-
.post(
|
|
544
|
-
'/oauth2/token',
|
|
545
|
-
utils.readExampleFile('./test/unit/examples/oauthRequests/getTokenFromTrust.json', true)
|
|
546
|
-
)
|
|
547
|
-
.reply(
|
|
548
|
-
200,
|
|
549
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock.json'),
|
|
550
|
-
{}
|
|
551
|
-
);
|
|
552
|
-
|
|
553
|
-
contextBrokerMock = nock('http://192.168.1.1:1026')
|
|
554
|
-
.matchHeader('fiware-service', 'smartGondor')
|
|
555
|
-
.matchHeader('fiware-servicepath', 'electricity')
|
|
556
|
-
.matchHeader('Authorization', 'Bearer c1b752e377680acd1349a3ed59db855a1db07605')
|
|
557
|
-
.post(
|
|
558
|
-
'/v1/updateContext',
|
|
559
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext1.json')
|
|
560
|
-
)
|
|
561
|
-
.reply(401, 'Auth-token not found in request header');
|
|
562
|
-
|
|
563
|
-
iotAgentLib.activate(iotAgentConfig, done);
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
it('it should return a ACCESS_FORBIDDEN error to the caller', function (done) {
|
|
567
|
-
iotAgentLib.update('light1', 'Light', '', values, function (error) {
|
|
568
|
-
should.exist(error);
|
|
569
|
-
error.name.should.equal('ACCESS_FORBIDDEN');
|
|
570
|
-
done();
|
|
571
|
-
});
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
describe(
|
|
577
|
-
'Secured access to the Context Broker with OAuth2 provider (FIWARE Keyrock IDM)' +
|
|
578
|
-
'configured through group provisioning',
|
|
579
|
-
function () {
|
|
580
|
-
const groupCreation = {
|
|
581
|
-
url: 'http://localhost:4041/iot/services',
|
|
582
|
-
method: 'POST',
|
|
583
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionFullGroup.json'),
|
|
584
|
-
headers: {
|
|
585
|
-
'fiware-service': 'TestService',
|
|
586
|
-
'fiware-servicepath': '/testingPath'
|
|
587
|
-
}
|
|
588
|
-
};
|
|
589
|
-
|
|
590
|
-
const values = [
|
|
591
|
-
{
|
|
592
|
-
name: 'status',
|
|
593
|
-
type: 'String',
|
|
594
|
-
value: 'STARTING'
|
|
595
|
-
}
|
|
596
|
-
];
|
|
597
|
-
|
|
598
|
-
beforeEach(function () {
|
|
599
|
-
logger.setLevel('FATAL');
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
afterEach(function (done) {
|
|
603
|
-
iotAgentLib.deactivate(done);
|
|
604
|
-
nock.cleanAll();
|
|
605
|
-
});
|
|
606
|
-
|
|
607
|
-
describe('When a measure is sent to the Context Broker via an Update Context operation', function () {
|
|
608
|
-
let oauth2Mock2;
|
|
609
|
-
let contextBrokerMock2;
|
|
610
|
-
beforeEach(function (done) {
|
|
611
|
-
nock.cleanAll();
|
|
612
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
613
|
-
.post(
|
|
614
|
-
'/oauth2/token',
|
|
615
|
-
utils.readExampleFile(
|
|
616
|
-
'./test/unit/examples/oauthRequests/getTokenFromTrustKeyrockGroup.json',
|
|
617
|
-
true
|
|
618
|
-
)
|
|
619
|
-
)
|
|
620
|
-
.reply(
|
|
621
|
-
200,
|
|
622
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock.json'),
|
|
623
|
-
{}
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
oauth2Mock2 = nock('http://192.168.1.1:3000')
|
|
627
|
-
.post(
|
|
628
|
-
'/oauth2/token',
|
|
629
|
-
utils.readExampleFile(
|
|
630
|
-
'./test/unit/examples/oauthRequests/getTokenFromTrustKeyrockGroup2.json',
|
|
631
|
-
true
|
|
632
|
-
)
|
|
633
|
-
)
|
|
634
|
-
.reply(
|
|
635
|
-
200,
|
|
636
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock2.json'),
|
|
637
|
-
{}
|
|
638
|
-
);
|
|
639
|
-
|
|
640
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
641
|
-
.matchHeader('fiware-service', 'TestService')
|
|
642
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
643
|
-
.matchHeader('Authorization', 'Bearer c1b752e377680acd1349a3ed59db855a1db07605')
|
|
644
|
-
.post(
|
|
645
|
-
'/v1/updateContext',
|
|
646
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext3WithStatic.json')
|
|
647
|
-
)
|
|
648
|
-
.reply(
|
|
649
|
-
200,
|
|
650
|
-
utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json')
|
|
651
|
-
);
|
|
652
|
-
|
|
653
|
-
contextBrokerMock2 = nock('http://unexistentHost:1026')
|
|
654
|
-
.matchHeader('fiware-service', 'TestService')
|
|
655
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
656
|
-
.matchHeader('Authorization', 'Bearer bbb752e377680acd1349a3ed59db855a1db076aa')
|
|
657
|
-
.post(
|
|
658
|
-
'/v1/updateContext',
|
|
659
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext3WithStatic.json')
|
|
660
|
-
)
|
|
661
|
-
.reply(
|
|
662
|
-
200,
|
|
663
|
-
utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json')
|
|
664
|
-
);
|
|
665
|
-
iotAgentConfig.authentication.tokenPath = '/oauth2/token';
|
|
666
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
667
|
-
request(groupCreation, function (error, response, body) {
|
|
668
|
-
done();
|
|
669
|
-
});
|
|
670
|
-
});
|
|
671
|
-
});
|
|
672
|
-
it(
|
|
673
|
-
'should ask OAuth2 provider for a token based on the' +
|
|
674
|
-
'trust token and send the generated token in the auth header',
|
|
675
|
-
function (done) {
|
|
676
|
-
iotAgentLib.update('machine1', 'SensorMachine', '', values, function (error) {
|
|
677
|
-
should.not.exist(error);
|
|
678
|
-
oauth2Mock.done();
|
|
679
|
-
contextBrokerMock.done();
|
|
680
|
-
done();
|
|
681
|
-
});
|
|
682
|
-
}
|
|
683
|
-
);
|
|
684
|
-
|
|
685
|
-
it('should use the updated trust token in the following requests', function (done) {
|
|
686
|
-
iotAgentLib.update('machine1', 'SensorMachine', '', values, function (error) {
|
|
687
|
-
should.not.exist(error);
|
|
688
|
-
oauth2Mock2.done();
|
|
689
|
-
contextBrokerMock2.done();
|
|
690
|
-
done();
|
|
691
|
-
});
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
|
-
|
|
695
|
-
describe('When a device is provisioned for a configuration contains an OAuth2 trust token', function () {
|
|
696
|
-
const values = [
|
|
697
|
-
{
|
|
698
|
-
name: 'status',
|
|
699
|
-
type: 'String',
|
|
700
|
-
value: 'STARTING'
|
|
701
|
-
}
|
|
702
|
-
];
|
|
703
|
-
const deviceCreation = {
|
|
704
|
-
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
|
|
705
|
-
method: 'POST',
|
|
706
|
-
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionNewDevice2.json'),
|
|
707
|
-
headers: {
|
|
708
|
-
'fiware-service': 'TestService',
|
|
709
|
-
'fiware-servicepath': '/testingPath'
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
let contextBrokerMock2;
|
|
713
|
-
let contextBrokerMock3;
|
|
714
|
-
beforeEach(function (done) {
|
|
715
|
-
nock.cleanAll();
|
|
716
|
-
|
|
717
|
-
oauth2Mock = nock('http://192.168.1.1:3000')
|
|
718
|
-
.post(
|
|
719
|
-
'/oauth2/token',
|
|
720
|
-
utils.readExampleFile(
|
|
721
|
-
'./test/unit/examples/oauthRequests/getTokenFromTrustKeyrockGroup3.json',
|
|
722
|
-
true
|
|
723
|
-
)
|
|
724
|
-
)
|
|
725
|
-
.reply(
|
|
726
|
-
200,
|
|
727
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock3.json'),
|
|
728
|
-
{}
|
|
729
|
-
)
|
|
730
|
-
.post(
|
|
731
|
-
'/oauth2/token',
|
|
732
|
-
utils.readExampleFile(
|
|
733
|
-
'./test/unit/examples/oauthRequests/getTokenFromTrustKeyrockGroup4.json',
|
|
734
|
-
true
|
|
735
|
-
)
|
|
736
|
-
)
|
|
737
|
-
.reply(
|
|
738
|
-
200,
|
|
739
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock4.json'),
|
|
740
|
-
{}
|
|
741
|
-
)
|
|
742
|
-
.post(
|
|
743
|
-
'/oauth2/token',
|
|
744
|
-
utils.readExampleFile(
|
|
745
|
-
'./test/unit/examples/oauthRequests/getTokenFromTrustKeyrockGroup5.json',
|
|
746
|
-
true
|
|
747
|
-
)
|
|
748
|
-
)
|
|
749
|
-
.reply(
|
|
750
|
-
200,
|
|
751
|
-
utils.readExampleFile('./test/unit/examples/oauthResponses/tokenFromTrustKeyrock5.json'),
|
|
752
|
-
{}
|
|
753
|
-
);
|
|
754
|
-
|
|
755
|
-
contextBrokerMock = nock('http://unexistenthost:1026')
|
|
756
|
-
.matchHeader('fiware-service', 'TestService')
|
|
757
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
758
|
-
.matchHeader('Authorization', 'Bearer asd752e377680acd1349a3ed59db855a1db07ere')
|
|
759
|
-
.post(
|
|
760
|
-
'/NGSI9/registerContext',
|
|
761
|
-
utils.readExampleFile(
|
|
762
|
-
'./test/unit/examples/contextAvailabilityRequests/registerProvisionedDeviceWithGroup2.json'
|
|
763
|
-
)
|
|
764
|
-
)
|
|
765
|
-
.reply(
|
|
766
|
-
200,
|
|
767
|
-
utils.readExampleFile(
|
|
768
|
-
'./test/unit/examples/contextAvailabilityResponses/registerProvisionedDeviceSuccess.json'
|
|
769
|
-
)
|
|
770
|
-
);
|
|
771
|
-
|
|
772
|
-
contextBrokerMock2 = nock('http://unexistenthost:1026')
|
|
773
|
-
.matchHeader('fiware-service', 'TestService')
|
|
774
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
775
|
-
.matchHeader('authorization', 'Bearer bea752e377680acd1349a3ed59db855a1db07zxc')
|
|
776
|
-
.post(
|
|
777
|
-
'/v1/updateContext',
|
|
778
|
-
utils.readExampleFile(
|
|
779
|
-
'./test/unit/examples/contextRequests/createProvisionedDeviceWithGroupAndStatic2.json'
|
|
780
|
-
)
|
|
781
|
-
)
|
|
782
|
-
.reply(
|
|
783
|
-
200,
|
|
784
|
-
utils.readExampleFile(
|
|
785
|
-
'./test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json'
|
|
786
|
-
)
|
|
787
|
-
);
|
|
788
|
-
|
|
789
|
-
contextBrokerMock3 = nock('http://unexistentHost:1026')
|
|
790
|
-
.matchHeader('fiware-service', 'TestService')
|
|
791
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
792
|
-
.matchHeader('authorization', 'Bearer zzz752e377680acd1349a3ed59db855a1db07bbb')
|
|
793
|
-
.post(
|
|
794
|
-
'/v1/updateContext',
|
|
795
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext4.json')
|
|
796
|
-
)
|
|
797
|
-
.reply(
|
|
798
|
-
200,
|
|
799
|
-
utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json')
|
|
800
|
-
);
|
|
801
|
-
|
|
802
|
-
iotAgentConfig.authentication.tokenPath = '/oauth2/token';
|
|
803
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
804
|
-
done();
|
|
805
|
-
});
|
|
806
|
-
});
|
|
807
|
-
|
|
808
|
-
it('should not raise any error', function (done) {
|
|
809
|
-
request(deviceCreation, function (error, response, body) {
|
|
810
|
-
should.not.exist(error);
|
|
811
|
-
response.statusCode.should.equal(201);
|
|
812
|
-
contextBrokerMock.done();
|
|
813
|
-
contextBrokerMock2.done();
|
|
814
|
-
done();
|
|
815
|
-
});
|
|
816
|
-
});
|
|
817
|
-
|
|
818
|
-
it('should send the mixed data to the Context Broker', function (done) {
|
|
819
|
-
iotAgentLib.update('Light1', 'SensorMachine', '', values, function (error) {
|
|
820
|
-
should.not.exist(error);
|
|
821
|
-
contextBrokerMock3.done();
|
|
822
|
-
done();
|
|
823
|
-
});
|
|
824
|
-
});
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
|
-
);
|
|
828
|
-
|
|
829
|
-
describe(
|
|
830
|
-
'Secured access to the Context Broker with OAuth2 provider (FIWARE Keyrock IDM)' +
|
|
831
|
-
'configured through group provisioning. Permanent token',
|
|
832
|
-
function () {
|
|
833
|
-
const groupCreation = {
|
|
834
|
-
url: 'http://localhost:4041/iot/services',
|
|
835
|
-
method: 'POST',
|
|
836
|
-
json: utils.readExampleFile('./test/unit/examples/groupProvisioningRequests/provisionFullGroup.json'),
|
|
837
|
-
headers: {
|
|
838
|
-
'fiware-service': 'TestService',
|
|
839
|
-
'fiware-servicepath': '/testingPath'
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
const values = [
|
|
844
|
-
{
|
|
845
|
-
name: 'status',
|
|
846
|
-
type: 'String',
|
|
847
|
-
value: 'STARTING'
|
|
848
|
-
}
|
|
849
|
-
];
|
|
850
|
-
|
|
851
|
-
beforeEach(function () {
|
|
852
|
-
logger.setLevel('FATAL');
|
|
853
|
-
iotAgentConfig.authentication.permanentToken = true;
|
|
854
|
-
});
|
|
855
|
-
|
|
856
|
-
afterEach(function (done) {
|
|
857
|
-
iotAgentLib.deactivate(done);
|
|
858
|
-
nock.cleanAll();
|
|
859
|
-
});
|
|
860
|
-
|
|
861
|
-
describe('When a measure is sent to the Context Broker via an Update Context operation', function () {
|
|
862
|
-
beforeEach(function (done) {
|
|
863
|
-
nock.cleanAll();
|
|
864
|
-
|
|
865
|
-
contextBrokerMock = nock('http://unexistentHost:1026')
|
|
866
|
-
.matchHeader('fiware-service', 'TestService')
|
|
867
|
-
.matchHeader('fiware-servicepath', '/testingPath')
|
|
868
|
-
.matchHeader('Authorization', 'Bearer 999210dacf913772606c95dd0b895d5506cbc988')
|
|
869
|
-
.post(
|
|
870
|
-
'/v1/updateContext',
|
|
871
|
-
utils.readExampleFile('./test/unit/examples/contextRequests/updateContext3WithStatic.json')
|
|
872
|
-
)
|
|
873
|
-
.reply(
|
|
874
|
-
200,
|
|
875
|
-
utils.readExampleFile('./test/unit/examples/contextResponses/updateContext1Success.json')
|
|
876
|
-
);
|
|
877
|
-
|
|
878
|
-
iotAgentConfig.authentication.tokenPath = '/oauth2/token';
|
|
879
|
-
iotAgentLib.activate(iotAgentConfig, function () {
|
|
880
|
-
request(groupCreation, function (error, response, body) {
|
|
881
|
-
done();
|
|
882
|
-
});
|
|
883
|
-
});
|
|
884
|
-
});
|
|
885
|
-
it('should send the permanent token in the auth header', function (done) {
|
|
886
|
-
iotAgentLib.update('machine1', 'SensorMachine', '', values, function (error) {
|
|
887
|
-
should.not.exist(error);
|
|
888
|
-
contextBrokerMock.done();
|
|
889
|
-
done();
|
|
890
|
-
});
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
it('should use the permanent trust token in the following requests', function (done) {
|
|
894
|
-
iotAgentLib.update('machine1', 'SensorMachine', '', values, function (error) {
|
|
895
|
-
should.not.exist(error);
|
|
896
|
-
contextBrokerMock.done();
|
|
897
|
-
done();
|
|
898
|
-
});
|
|
899
|
-
});
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
);
|