diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index e976dd5c9b..0000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,30 +0,0 @@ - - - -- **OS and version used:** - -- **SDK version used:** - - -# Description of the issue: - - -# Code sample exhibiting the issue: - - -# Console log of the issue: - - - diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 0000000000..7effcb9e8b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,81 @@ +--- +name: Bug Report +about: Create a bug report to help us improve +title: '' +labels: +assignees: '' + +--- + +------------------------------- delete below ------------------------------- + +INSTRUCTIONS +========== + +Please follow the instructions and template below to save us time requesting additional information from you. + +1. Search existing issues to avoid creating duplicates. + +2. If possible test using the latest release to make sure your issues has not already been fixed: +https://github.com/Azure/azure-iot-sdk-c/releases/latest + +3. Do not share information from your Azure subscription here (connection strings, service names (IoT Hub name, Device Provisioning Service scope ID), etc...). If you need to share any of this information, you can create a ticket and get assistance from the Microsoft Support. + +How to Submit an Azure Support Ticket: https://docs.microsoft.com/en-us/azure/azure-supportability/how-to-create-azure-support-request + + +4. Include enough information for us to address the bug: + + - A detailed description. + - A Minimal Complete Reproducible Example (https://stackoverflow.com/help/mcve). This is code we can cut and paste into a readily available sample and run, or a link to a project you've written that we can compile to reproduce the bug. + - Console logs. If you are unsure how to enable logging, refer to this document: https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/Iothub_sdk_options.md + +5. Delete these instructions before submitting the bug. + + + +Below is a hypothetical bug report. We recommend you use it as a template and replace the information below each header with your own. + +------------------------------- delete above ------------------------------- + + +**Development Machine, OS, Compiler (and Other Relevant Toolchain Info)** + +Raspberry Pi, Raspbian Stretch Lite (Release 2018-11-13) +Cross Compiled on Ubuntu 18.04 using GCC 6.3.0 + +**SDK Version (Please Give Commit SHA if Manually Compiling)** + +Release 2019-01-31 + +**Protocol** + +MQTT + +**Describe the Bug** + +If MQTT is unable to establish a connection, it will keep trying and once it succeeds queued messages will be sent to the Cloud. However, if for some reason we can't get past the initial connection phase, then SDK does not respect message timeouts. + +**[MCVE](https://stackoverflow.com/help/mcve)** + +``` +#include "iothub.h" + +int main(void) +{ + if (lightbulb == ON) { + iothub_say_hello(); + return 0; + } else { + iothub_say_goodbye(); + return 1; + } +} +``` + +**Console Logs** + +Sending message 1 to IoTHub +-> 15:07:42 PUBLISH | IS_DUP: false | RETAIN: 0 | QOS: DELIVER_AT_LEAST_ONCE | TOPIC_NAME: devices/tracingDevice/messages/events/property_key=property_value | PACKET_ID: 93 | PAYLOAD_LEN: 12 +<- 15:07:42 PUBACK | PACKET_ID: 92 +Confirmation callback received for message 86 with result IOTHUB_CLIENT_CONFIRMATION_OK diff --git a/.github/ISSUE_TEMPLATE/feature-request.md b/.github/ISSUE_TEMPLATE/feature-request.md new file mode 100644 index 0000000000..4e16703e6e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.md @@ -0,0 +1,33 @@ +--- +name: Feature Request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +------------------------------- delete below ------------------------------- + +Thank you for submitting a feature request. A few things: + +- Please check that a similar feature request has not already been submitted. Adding support to a currently existing feature request by commenting will increase the visibility and importance of your request beyond submitting a duplicate request. + +- If this is a large feature request (i.e. if it requires changes across multiple language SDKs), please submit it to user voice. +https://feedback.azure.com/forums/321918-azure-iot + +As an open source project, we welcome PRs for new features, and we don't want to reject any hard work you've done to contribute. **So propose your solution through an issue first** so we can discuss the changes, and if things look good we will ask you submit a PR to implement the changes. + +------------------------------- delete above ------------------------------- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/technical-question.md b/.github/ISSUE_TEMPLATE/technical-question.md new file mode 100644 index 0000000000..c2da20052e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/technical-question.md @@ -0,0 +1,20 @@ +--- +name: Technical Question +about: Ask a technical question related to the SDK +title: '' +labels: question +assignees: '' + +--- + +------------------------------- delete below ------------------------------- + +Thank you for asking a technical question! If your question is "why doesn't my code work?", please submit a Bug issue instead. + +We also encourage users to submit technical questions related to the SDK on Stack Overflow. + +For Stack Overflow, simply submit a question with the tag "azure-iot-hub". + +If your technical question requires submitting service logs, you can submit an Azure Support Ticket: https://docs.microsoft.com/en-us/azure/azure-supportability/how-to-create-azure-support-request + +------------------------------- delete above ------------------------------- diff --git a/build/.horton-e2e.yml b/build/.horton-e2e.yml new file mode 100644 index 0000000000..48cab5cbe9 --- /dev/null +++ b/build/.horton-e2e.yml @@ -0,0 +1,20 @@ +variables: + Horton.FrameworkRoot: $(Agent.BuildDirectory)/e2e-fx + Horton.FrameworkRef: master + Horton.Language: c + Horton.Repo: $(Build.Repository.Uri) + Horton.Commit: $(Build.SourceBranch) + Horton.ForcedImage: '' + +resources: + repositories: + - repository: e2e_fx + type: github + name: Azure/iot-sdks-e2e-fx + ref: refs/heads/master + endpoint: 'GitHub OAuth - az-iot-builder-01' + +jobs: +- template: vsts/templates/jobs-gate-c.yaml@e2e_fx + + diff --git a/build_all/docs/Doxyfile b/build_all/docs/Doxyfile index 5b33753ec8..0f3710a96a 100644 --- a/build_all/docs/Doxyfile +++ b/build_all/docs/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = "Microsoft Azure IoT Device SDK for C" # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.2.12 +PROJECT_NUMBER = 1.3.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/c-utility b/c-utility index 773980d788..bc83cba123 160000 --- a/c-utility +++ b/c-utility @@ -1 +1 @@ -Subproject commit 773980d7882e4d5f1e7c9be2a0797d61fbc19da1 +Subproject commit bc83cba1230e98988ae5cd2328f4dcf8c49d5866 diff --git a/deps/uhttp b/deps/uhttp index 3a81e598ca..43dce924b3 160000 --- a/deps/uhttp +++ b/deps/uhttp @@ -1 +1 @@ -Subproject commit 3a81e598caf2bd37077b7cd20bb45aaa9e694df7 +Subproject commit 43dce924b32818f8ab851f972cffebc204edc5c4 diff --git a/doc/Docker_SDK_Cross_Compile.md b/doc/Docker_SDK_Cross_Compile.md index 7c700caff2..8f22ac2e30 100644 --- a/doc/Docker_SDK_Cross_Compile.md +++ b/doc/Docker_SDK_Cross_Compile.md @@ -15,16 +15,21 @@ The Docker container is based on the latest Ubuntu Docker container. From there * nano - in case one needs to edit any files in the Docker container Once this is complete, the script will acquire all of the prerequisites. These are: -* The toolchain that will build binaries for our target platform. You should substitute the toolchain for your target platform. +* The toolchain that will build binaries for our target platform. You should substitute the toolchain for your target platform * [The IoT SDK source code](https://github.com/azure/azure-iot-sdk-c). -* [OpenSSL](https://www.openssl.org/) at version 1.0.2o. -* [cURL](https://curl.haxx.se/) at version 7.60.0. +* [OpenSSL](https://www.openssl.org/) - version 1.0.2o used +* [cURL](https://curl.haxx.se/) - version 7.60.0 used * [util-linux](https://en.wikipedia.org/wiki/Util-linux) for uuid functionality. With all of those in place we can build OpenSSL, cURL, and libuuid. These will be installed into the toolchain as each is built and will be used in the final step when the SDK itself is built. +## Major Tasks +You will need to identify a suitable toolchain for your target platform and modify the line that downloads this toolchain in your Docker script. + +Once this is done, then the environment variable set below will need to be modified to reflect the location and directory names of that toolchain. Once these have been updated then the Docker script should be ready to run. + ## The Docker Script -Here is the script: +Here is an example script: ```docker # Start with the latest version of the Ubuntu Docker container FROM ubuntu:latest @@ -48,6 +53,11 @@ WORKDIR /home/builder RUN mkdir MIPSBuild WORKDIR MIPSBuild +# +# The following wget invocation will need to be modified to download a toolchain appropriate +# for your target device. +# + # Download the WRTNode cross compile toolchain and expand it RUN wget https://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620n/OpenWrt-Toolchain-ramips-for-mipsel_24kec%2bdsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 RUN tar -xvf OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 @@ -67,8 +77,10 @@ RUN tar -xvf curl-7.60.0.tar.gz RUN wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.32/util-linux-2.32-rc2.tar.gz RUN tar -xvf util-linux-2.32-rc2.tar.gz +# # Set up environment variables in preparation for the builds to follow -# These will need to be modified for the corresponding locations in the toolchain being used +# These will need to be modified for the corresponding locations in the downloaded toolchain +# ENV WORK_ROOT=/home/builder/MIPSBuild ENV TOOLCHAIN_ROOT=${WORK_ROOT}/OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2 ENV TOOLCHAIN_SYSROOT=${TOOLCHAIN_ROOT}/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2 @@ -142,16 +154,17 @@ WORKDIR ../.. To run this script save it to a directory and change to that directory then simply enter: ```bash -docker build -t mipsbuild:latest . --network=host +docker build -t mipsiotbuild:latest . --network=host ``` -You can replace the value 'mipsbuild' with any name that describes your build. In this instance it is building for a MIPS32 processor hence the name. Once the build is complete you will be ready to build your application against the libraries just built. +You can replace the value 'mipsiotbuild' with any name that describes your build. In this instance it is building for a MIPS32 processor hence the name. Once the build is complete you will be ready to build your application against the libraries just built. *Note:* The build of the Azure IoT C SDK uses cmake to generate the makefiles. In order to instruct cmake to perform a cross-compile one uses a cmake toolchain file. This tells cmake where to find the libraries etc. in the toolchain rather than on the host. This file is created on the fly in the above script to reduce dependencies on external files. Alternatively one could create this file outside the script and import into the container. + ## Building Your Application -Once you have successfully built the SDK you are now ready to create your application. Your application will also need to be cross compiled so adding additional steps to the end of the Dockerfile script to build your code is likely the easiest way to accomplish this. If you set up your application to also build with cmake then you can simply use the cmake toolchain file created to build the SDK. +Once you have successfully built the SDK you are now ready to create your application. You will need to create a directory that contains your source code and a CMakeLists.txt. The application build can use the cmake toolchain file that is already present in the image. ### Sample ```CMakeLists.txt``` for an Application -Here is a simple ```CMakeLists.txt``` file that demonstrates how to build an application that uses the libraries built above. This sample, for demonstration purposes uses the ```iothub_convenience_sample.c``` sample from the SDK. +Here is a simple ```CMakeLists.txt``` file that demonstrates how to build an application that uses the libraries built above. This sample, for demonstration purposes uses a copy of the ```iothub_convenience_sample.c``` sample from the SDK. ```cmake cmake_minimum_required(VERSION 2.8.11) project(myapp_project) @@ -183,17 +196,24 @@ link_directories($ENV{TOOLCHAIN_PREFIX}/lib) add_executable(myapp ${iothub_c_files}) -# Redundant in this case but shows how to rename your output executable +# Redundant in this case but demonstrates how to rename your output executable set_target_properties(myapp PROPERTIES OUTPUT_NAME "myapp") # List the libraries required by the link step target_link_libraries(myapp iothub_client_mqtt_transport iothub_client umqtt aziotsharedutil parson pthread curl ssl crypto m ) ``` -### Sample Additions to Dockerfile to build the application -This sample assumes that you have a subdirectory in the directory containing your Dockerfile called myapp. In this directory are the CMakeLists.txt file above and your code to be built. This will be copied to your Docker container and built. This fragment would be appended to the sample above. +### Using a Separate Docker Script to Build the Application +Though one could append the application build steps to the Docker script above, this will demonstrate how to use the existing image and build the application in a seperate Docker script. This will keep the original image clean so it may be used for building multiple applications. + +This sample script assumes you have your source files and the ```CMakeLists.txt``` in a directory called ```myapp```. ```docker +FROM mipsiotbuild:latest + +USER builder +WORKDIR /home/builder + # Copy a directory from the host containing the files to build setting ownership at the same time -ADD --chown=builder:builder myapp ${WORK_ROOT}/myapp +ADD --chown=builder:builder myapp myapp # Sanity check RUN ls -al myapp @@ -212,21 +232,53 @@ RUN make # There should be an executable called myapp RUN ls -al myapp ``` -## Copying the Executable from the Docker Container -The last step is to copy the new executable from your Docker container to your host so that it can be deployed to your target device. -Find out what your container is called, in this case it's vibrant_goodall. +Execute this Docker script with: ``` -markrad@markradubuh:~/MIPS32cc$ docker container ls -a -CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -c6f501066027 259c8fe3911f "/bin/bash" 5 minutes ago Exited (0) 5 minutes ago vibrant_goodall +docker build -t mipsiotapp:latest . --network=host ``` -Copy the executable from the container to your local file system. +## Copying the Executable from the Docker Container +Now the applicaton is built the last step is to copy the new executable from your Docker container to your host so that it can be deployed to your target device. An example of how you might do this follows: + ``` -docker cp vibrant_goodall:/home/builder/MIPSBuild/myapp/cmake/myapp ./myapp_exe +id =$(docker create mipsiotapp) +docker cp $id:/home/builder/myapp/cmake/myapp ./myapp_exe +docker rm -v $id ``` -This will copy the executable to your local host and rename it to myapp_exe. If all has worked well then a ```file``` command executed against ```myapp_exe``` should, in this case, show as an ELF 32 bit MIPS32. +The above steps will create and acquire the Docker container identifier, copy the application to the local directory on the host and then delete the container. -**Note:** Depending upon your device you may need to copy additional binaries from the container in order to add them to your device. For example you device may not have the OpenSSL binaries so you will need to copy libssl.so and libcrypto.so. This could also be true for libuuid and libcurl. All of these libraries will be in the toolchain. +**Note:** Depending upon your device you may need to copy additional binaries from the container in order to add them to your device. For example you device may not have the OpenSSL binaries so you will need to copy libssl.so and libcrypto.so. This could also be true for libuuid and libcurl. All of these libraries will be in the toolchain typically in ```/usr/local/lib```. +# A Complete Example +You can find two complete examples in [samples](../samples/dockerbuilds). This directory contains Docker scripts to cross compile the SDK for MIPS32 and for Raspbian and subsequently builds an application. In order to reduce the number of files required, the steps are slightly modified though they perform the same function. To cross compile the SDK for Raspbian, create an application and copy it to your host use the following steps. +```bash +# Change directory to your Azure IoT SDK cloned repository root +cd +# Work in this directory or two copies of the myapp directory will be required +cd samples/dockerbuilds +# Cross compile the SDK +docker build -t rpiiotbuild:latest ./RaspberryPi --network=host +# Build the application against the SDK +docker build -t rpiiotapp:latest . --network=host --file ./RaspberryPi/Dockerfile_adjunct +id=$(docker create rpiiotapp) +# Copy application to home directory +docker cp $id:/home/builder/myapp/cmake/myapp ~/myapp_rpi +docker rm -v $id +``` +And for MIPS32: +```bash +# Change directory to your Azure IoT SDK cloned repository root +cd +# Work in this directory or two copies of the myapp directory will be required +cd samples/dockerbuilds +# Cross compile the SDK +docker build -t mipsiotbuild:latest ./MIPS32 --network=host +# Build the application against the SDK +docker build -t mipsiotapp:latest . --network=host --file ./MIPS32/Dockerfile_adjunct +id=$(docker create mipsiotapp) +# Copy application to home directory +docker cp $id:/home/builder/myapp/cmake/myapp ~/myapp_mips +docker rm -v $id +``` +**Note:** For these examples to work successfully the image names must be exactly as they are shown in the examples. ## Summing Up This document demonstrates how to compile the Azure IoT SDK for C along with all of its dependents and then create and link an application with the libraries and headers. It uses a MIPS32 toolchain for this demonstration but it should be easily adaptable to the toolchain required by the target device. diff --git a/doc/connection_and_messaging_reliability.md b/doc/connection_and_messaging_reliability.md index 0f3b61579c..a5e0ad60c1 100644 --- a/doc/connection_and_messaging_reliability.md +++ b/doc/connection_and_messaging_reliability.md @@ -236,11 +236,11 @@ The [current retry policies](https://github.com/Azure/azure-iot-sdk-c/blob/2018- |IOTHUB_CLIENT_RETRY_NONE|No re-connections are ever attempted.|Usually this option is used along with Connection Status callbacks by users that want to implement their own connection retry logic (at the application layer).| |IOTHUB_CLIENT_RETRY_NONE|No re-connections are ever attempted.
Usually this option is used along with Connection Status callbacks by users that want to implement their own connection retry logic (at the application layer).|Device client detects a connection issue, but it never attempts to reconnect.| |IOTHUB_CLIENT_RETRY_IMMEDIATE|Re-connections shall be tried immediatelly, with no wait time in between attempts|Device client detects a connection issue.

The re-connection attempts happen immediatelly in a loop with no wait time until one succeeds| -|IOTHUB_CLIENT_RETRY_INTERVAL|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a fixed-interval* wait time (5 seconds by default).

* can be set by the user|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again every 5 seconds until it succeeds| -|IOTHUB_CLIENT_RETRY_LINEAR_BACKOFF|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a wait time that grows linearly.

Default behavior: starts from 5 seconds and grows by increments* of 5 seconds each time.

* can be set by the user|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again every 5 seconds until it succeeds| -|IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a wait time that grows exponentially.

Default behavior: starts from 1 second* and doubles each time.

* can be set by the user|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again in 1 second, then again 2 seconds, 4 seconds, 8 seconds, 16, 32, 64, ... until it succeeds.| -|IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a wait time that grows exponentially but with a random jitter deduction.

Default behavior: starts from 1 second* and doubles each time minus a random jitter of zero to one-hundred percent.

* can be set by the user|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again in 1 second, then again 1 second (-100% jitter), 2 seconds (0% jitter), 3 seconds (-50% jitter), 6 (0% jitter), 10 (-67% jitter), 19 (-10% jitter), ... until it succeeds.| -|IOTHUB_CLIENT_RETRY_RANDOM|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a random wait time.

Default behavior: the random wait time range* is from 0 to 5 seconds.

* can be set by the user|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again in 5 seconds (random multiplier of 100%), then again 2 seconds ( (random multiplier of 40%), 4 seconds (random multiplier of 80%), 0 seconds (random multiplier of 0%), 3 (60%), ... until it succeeds.| +|IOTHUB_CLIENT_RETRY_INTERVAL|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a fixed-interval wait time (5 seconds by default).

|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again every 5 seconds until it succeeds| +|IOTHUB_CLIENT_RETRY_LINEAR_BACKOFF|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a wait time that grows linearly.

Default behavior: starts from 5 seconds and grows by increments of 5 seconds each time.

|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again every 5 seconds until it succeeds| +|IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a wait time that grows exponentially.

Default behavior: starts from 1 second and doubles each time.

|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again in 1 second, then again 2 seconds, 4 seconds, 8 seconds, 16, 32, 64, ... until it succeeds.| +|IOTHUB_CLIENT_RETRY_EXPONENTIAL_BACKOFF_WITH_JITTER|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a wait time that grows exponentially but with a random jitter deduction.

Default behavior: starts from 1 second and doubles each time minus a random jitter of zero to one-hundred percent.

|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again in 1 second, then again 1 second (-100% jitter), 2 seconds (0% jitter), 3 seconds (-50% jitter), 6 (0% jitter), 10 (-67% jitter), 19 (-10% jitter), ... until it succeeds.| +|IOTHUB_CLIENT_RETRY_RANDOM|First attempt should be done immediatelly.

Until the re-connection succeeds, each subsequent attempt is subject to a random wait time.

Default behavior: the random wait time range is from 0 to 5 seconds.

|Device client detects a connection issue.

The first re-connection attempt happens immediatelly, then again in 5 seconds (random multiplier of 100%), then again 2 seconds ( (random multiplier of 40%), 4 seconds (random multiplier of 80%), 0 seconds (random multiplier of 0%), 3 (60%), ... until it succeeds.| ### Connection Status Callback diff --git a/doc/devbox_setup.md b/doc/devbox_setup.md index bc91431dac..3a2e68ccfc 100644 --- a/doc/devbox_setup.md +++ b/doc/devbox_setup.md @@ -13,7 +13,7 @@ This document describes how to prepare your development environment to use the * ## Set up a Windows development environment - Install [Visual Studio 2017][visual-studio]. You can use the **Visual Studio Community** Free download if you meet the licensing requirements. (**Visual Studio 2015** is also supported.) -> Be sure to include Visual C++ and NuGet Package Manager. +> Be sure to include Visual C++. - Install [git]. Confirm git is in your PATH by typing `git version` from a command prompt. @@ -32,6 +32,8 @@ git clone -b --recursive https://github.com/Azure/azure-iot-sdk-c.g ### Build a sample application without building the SDK +The sample applications build with the help of C SDK libraries and headers published from vcpkg (a library manager). To install the C SDK libraries and headers, follow the steps to [Setup C SDK vcpkg for Windows development environment](https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/setting_up_vcpkg.md#setup-c-sdk-vcpkg-for-windows-development-environment). + To quickly build one of our sample applications, open the corresponding [solution file][sln-file] (.sln) in Visual Studio. For example, to build the **telemetry message sample**, open **iothub_client\samples\iothub_ll_telemetry_sample\windows\iothub_ll_telemetry_sample.sln**. @@ -43,7 +45,7 @@ static const char* connectionString = "[device connection string]"; ...and replace `[device connection string]` with a valid device connection string for a device registered with your IoT Hub. For more information, see the [samples section](#samplecode) below. -Build the sample project. As part of the build, [NuGet] Package Manager will download packages for dependencies so you don't have to build the entire SDK. See **windows\packages.config** for the list of packages that will be downloaded. +Build the sample project. ### Build the C SDK in Windows @@ -340,67 +342,6 @@ with
The example above assumes curl 7.58 has been compiled and saved into `/usr/local/Cellar/curl/7.58.0`. For more details please see section "Upgrade CURL on Mac OS". - - -## [**DEPRECATED**: Set up a Windows Embedded Compact 2013 development environment -***WINDOWS EMBEDDED COMPACT 2013 RECEIVES MINIMAL SUPPORT FROM AZURE IOT SDK.*** In particular please be aware: -* No new features will be added to WEC. -* The only supported protocol is HTTPS. Popular protocols like AMQP and MQTT, both over TCP directly and over WebSockets, are not and will not be supported. -* HTTPS over proxy is not supported. -* Developers may want to evaluate [Windows 10 IoT Core], which has much broader Azure IoT SDK support. - -**SETUP INSTRUCTIONS FOR WINDOWS EMBEDDED COMPACT 2013** - -- Install [Visual Studio 2015][visual-studio]. You can use the **Visual Studio Community** Free download if you meet the licensing requirements. - > Be sure to include Visual C++ and NuGet Package Manager. - -- Install [Application Builder for Windows Embedded Compact 2013][application-builder] for Visual Studio 2015 -- Install [Toradex Windows Embedded Compact 2013 SDK][toradex-CE8-sdk] or your own SDK. - -- Install [git]. Confirm git is in your PATH by typing `git version` from a command prompt. - -- Install [CMake]. Make sure it is in your PATH by typing `cmake -version` from a command prompt. CMake will be used to create Visual Studio projects to build libraries and samples. - -- Locate the tag name for the [latest release][latest-release] of the SDK. - > Our release tag names are date values in `yyyy-mm-dd` format. - -- Clone the latest release of SDK to your local machine using the tag name you found: - - ```Shell - git clone -b --recursive https://github.com/Azure/azure-iot-sdk-c.git - ``` - - > The `--recursive` argument instructs git to clone other GitHub repos this SDK depends on. Dependencies are listed [here](https://github.com/Azure/azure-iot-sdk-c/blob/master/.gitmodules). - -If you installed a different SDK please check azure-iot-sdk-c\\build_all\\windowsce\\build.cmd and replace: - -```Shell -set SDKNAME=TORADEX_CE800 -set PROCESSOR=arm -``` - -with a reference to the name of the SDK and the processor architecture (arm/x86) you plan to use. - -### Verify your environment - -You can build the Windows samples to verify that your environment is set up correctly. - -- Open a "Developer Command Prompt for VS2015". -- Navigate to the **build_all\\windowsce** folder in your local copy of the repository. -- Run the following command: - -```Shell -build -``` - -This script uses CMake to create a folder called "cmake\_ce8" in your home directory and generates in that folder a Visual Studio solution called azure_iot_sdks.sln. The script will then proceed to build the **HTTP** sample. - -> Note: you will not be able to run the samples until you configure them with a valid IoT hub device connection string. For more information, see [running a C sample application on Windows Embedded Compact 2013 on a Toradex module](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/get_started/wince2013-toradex-module-c.md). - -To view the projects and examine the source code, open the **azure_iot_sdks.sln** solution file in Visual Studio. - -You can use one of the sample applications as a template to get started when you are creating your own client applications. - ## Sample applications @@ -436,7 +377,6 @@ make [azure-umqtt-c]:https://github.com/Azure/azure-umqtt-c [sln-file]:https://msdn.microsoft.com/en-us/library/bb165951.aspx [git]:http://www.git-scm.com -[NuGet]:https://www.nuget.org/ [CMake]:https://cmake.org/ [MSBuild]:https://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx [OpenSSL]:https://www.openssl.org/ diff --git a/doc/run_c_sdk_on_constrained_device.md b/doc/run_c_sdk_on_constrained_device.md index 167b1bbc30..a399b7f433 100644 --- a/doc/run_c_sdk_on_constrained_device.md +++ b/doc/run_c_sdk_on_constrained_device.md @@ -15,7 +15,7 @@ cmake -Duse_amqp=OFF -Duse_http=OFF There is extensive logging throughout the SDK. Every message will be included in the SDK's RAM and ROM footprint. Removing logging will reduce the size of your application. ```Shell -cmake -Duse_amqp=OFF -Duse_http=OFF -Dno_logging=OFF +cmake -Duse_amqp=OFF -Duse_http=OFF -Dno_logging=ON ``` ## Running the SDK without upload to blob @@ -23,7 +23,7 @@ cmake -Duse_amqp=OFF -Duse_http=OFF -Dno_logging=OFF Upload to blob is an SDK feature used to send data to Azure Storage. If your application doesn't need this feature you can remove the files ```Shell -cmake -Duse_amqp=OFF -Duse_http=OFF -Dno_logging=OFF -Ddont_use_uploadtoblob=ON +cmake -Duse_amqp=OFF -Duse_http=OFF -Dno_logging=ON -Ddont_use_uploadtoblob=ON ``` ## Running strip on Linux environment diff --git a/iothub_client/CMakeLists.txt b/iothub_client/CMakeLists.txt index bed1e2cb8c..63851d0853 100644 --- a/iothub_client/CMakeLists.txt +++ b/iothub_client/CMakeLists.txt @@ -35,6 +35,7 @@ set(iothub_client_h_files ./inc/iothub_client_core_common.h ./inc/iothub_client_ll.h ./inc/internal/iothub_client_diagnostic.h + ./inc/internal/iothub_internal_consts.h ./inc/iothub_client_options.h ./inc/internal/iothub_client_private.h ./inc/iothub_client_version.h diff --git a/iothub_client/devdoc/requirement_docs/iothubtransport_amqp_twin_messenger_requirements.md b/iothub_client/devdoc/requirement_docs/iothubtransport_amqp_twin_messenger_requirements.md index 5ea3cb3ab0..9f291cdee9 100644 --- a/iothub_client/devdoc/requirement_docs/iothubtransport_amqp_twin_messenger_requirements.md +++ b/iothub_client/devdoc/requirement_docs/iothubtransport_amqp_twin_messenger_requirements.md @@ -134,9 +134,7 @@ int twin_messenger_report_state_async(TWIN_TWIN_MESSENGER_HANDLE twin_msgr_handl **SRS_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_024: [**If malloc() fails, twin_messenger_report_state_async() shall fail and return a non-zero value**]** -**SRS_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_025: [**`twin_op_ctx` shall have a copy of `data`**]** - -**SRS_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_026: [**If `data` fails to be copied, twin_messenger_report_state_async() shall fail and return a non-zero value**]** +**SRS_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_025: [**`twin_op_ctx` shall increment the reference count for `data` and store it.**]** **SRS_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_027: [**`twin_op_ctx->time_enqueued` shall be set using get_time**]** diff --git a/iothub_client/inc/internal/iothub_internal_consts.h b/iothub_client/inc/internal/iothub_internal_consts.h new file mode 100644 index 0000000000..73884f86ef --- /dev/null +++ b/iothub_client/inc/internal/iothub_internal_consts.h @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +#ifndef IOTHUB_INTERNAL_CONST_H +#define IOTHUB_INTERNAL_CONST_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + static const char* IOTHUB_API_VERSION = "2017-11-08-preview"; + + static const char* SECURITY_INTERFACE_INTERNAL_ID = "iothub-interface-internal-id"; + static const char* SECURITY_INTERFACE_INTERNAL_ID_VALUE = "security*azureiot*com^SecurityAgent^1*0*0"; + static const char* SECURITY_INTERFACE_ID = "iothub-interface-id"; + static const char* SECURITY_INTERFACE_ID_MQTT = "ifid"; + static const char* SECURITY_INTERFACE_ID_VALUE = "http://security.azureiot.com/SecurityAgent/1.0.0"; + static const char* SECURITY_MESSAGE_SCHEMA = "iothub-message-schema"; + static const char* SECURITY_MESSAGE_SCHEMA_VALUE = "sevent"; + +#ifdef __cplusplus +} +#endif + +#endif /* IOTHUB_INTERNAL_CONST_H */ diff --git a/iothub_client/inc/iothub_client_version.h b/iothub_client/inc/iothub_client_version.h index ccabfe07fd..bc56797d1a 100644 --- a/iothub_client/inc/iothub_client_version.h +++ b/iothub_client/inc/iothub_client_version.h @@ -8,7 +8,7 @@ #ifndef IOTHUB_CLIENT_VERSION_H #define IOTHUB_CLIENT_VERSION_H -#define IOTHUB_SDK_VERSION "1.2.12" +#define IOTHUB_SDK_VERSION "1.3.0" #include "azure_c_shared_utility/umock_c_prod.h" diff --git a/iothub_client/inc/iothub_message.h b/iothub_client/inc/iothub_message.h index 403f7b369e..2e43f3316b 100644 --- a/iothub_client/inc/iothub_message.h +++ b/iothub_client/inc/iothub_message.h @@ -369,6 +369,25 @@ MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionDeviceId, IOTHUB_MES MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionDeviceId); +/** +* @brief Marks a IoTHub message as a security message. CAUTION: Security messages are special messages not easily accessable by the user. +* +* @param iotHubMessageHandle Handle to the message. +* +* @return Returns IOTHUB_MESSAGE_OK if the Security Message was set successfully +* or an error code otherwise. +*/ +MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetAsSecurityMessage, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle); + +/** +* @brief returns if this message is a IoTHub security message or not +* +* @param iotHubMessageHandle Handle to the message. +* +* @return Returns true if the Message is a security message false otherwise. +*/ +MOCKABLE_FUNCTION(, bool, IoTHubMessage_IsSecurityMessage, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle); + /** * @brief Frees all resources associated with the given message handle. * diff --git a/iothub_client/samples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.c b/iothub_client/samples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.c index f219e99d16..4b39d4998b 100644 --- a/iothub_client/samples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.c +++ b/iothub_client/samples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.c @@ -122,8 +122,11 @@ int main(void) // Set any option that are neccessary. // For available options please see the iothub_sdk_options.md documentation +#ifndef SAMPLE_HTTP + // Can not set this options in HTTP bool traceOn = true; IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_LOG_TRACE, &traceOn); +#endif #ifdef SET_TRUSTED_CERT_IN_SAMPLES // Setting the Trusted Certificate. This is only necessary on system with without diff --git a/iothub_client/src/blob.c b/iothub_client/src/blob.c index 132ce2f8bf..f6ddd86025 100644 --- a/iothub_client/src/blob.c +++ b/iothub_client/src/blob.c @@ -9,7 +9,7 @@ #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/xlogging.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/shared_util_options.h" BLOB_RESULT Blob_UploadBlock( @@ -44,11 +44,11 @@ BLOB_RESULT Blob_UploadBlock( } else { - STRING_HANDLE blockIdString = Base64_Encode_Bytes((const unsigned char*)temp, 6); + STRING_HANDLE blockIdString = Azure_Base64_Encode_Bytes((const unsigned char*)temp, 6); if (blockIdString == NULL) { /*Codes_SRS_BLOB_02_033: [ If any previous operation that doesn't have an explicit failure description fails then Blob_UploadMultipleBlocksFromSasUri shall fail and return BLOB_ERROR ]*/ - LogError("unable to Base64_Encode_Bytes"); + LogError("unable to Azure_Base64_Encode_Bytes"); result = BLOB_ERROR; } else diff --git a/iothub_client/src/iothub_client_authorization.c b/iothub_client/src/iothub_client_authorization.c index fb424bd285..35b18978cf 100644 --- a/iothub_client/src/iothub_client_authorization.c +++ b/iothub_client/src/iothub_client_authorization.c @@ -20,6 +20,7 @@ #define DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS 3600 #define INDEFINITE_TIME ((time_t)(-1)) +#define MIN_SAS_EXPIRY_TIME 5 // 5 seconds typedef struct IOTHUB_AUTHORIZATION_DATA_TAG { @@ -51,6 +52,44 @@ static int get_seconds_since_epoch(size_t* seconds) return result; } +static IOTHUB_AUTHORIZATION_DATA* initialize_auth_client(const char* device_id, const char* module_id) +{ + IOTHUB_AUTHORIZATION_DATA* result; + + /* Codes_SRS_IoTHub_Authorization_07_002: [IoTHubClient_Auth_Create shall allocate a IOTHUB_AUTHORIZATION_HANDLE that is needed for subsequent calls. ] */ + result = (IOTHUB_AUTHORIZATION_DATA*)malloc(sizeof(IOTHUB_AUTHORIZATION_DATA) ); + if (result == NULL) + { + /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ + LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA"); + result = NULL; + } + else + { + memset(result, 0, sizeof(IOTHUB_AUTHORIZATION_DATA) ); + if (mallocAndStrcpy_s(&result->device_id, device_id) != 0) + { + /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ + LogError("Failed allocating device_key"); + free(result); + result = NULL; + } + else if (module_id != NULL && mallocAndStrcpy_s(&result->module_id, module_id) != 0) + { + /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ + LogError("Failed allocating module_id"); + free(result->device_id); + free(result); + result = NULL; + } + else + { + result->token_expiry_time_sec = DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS; + } + } + return result; +} + IOTHUB_AUTHORIZATION_HANDLE IoTHubClient_Auth_Create(const char* device_key, const char* device_id, const char* device_sas_token, const char *module_id) { IOTHUB_AUTHORIZATION_DATA* result; @@ -62,70 +101,46 @@ IOTHUB_AUTHORIZATION_HANDLE IoTHubClient_Auth_Create(const char* device_key, con } else { - /* Codes_SRS_IoTHub_Authorization_07_002: [IoTHubClient_Auth_Create shall allocate a IOTHUB_AUTHORIZATION_HANDLE that is needed for subsequent calls. ] */ - result = (IOTHUB_AUTHORIZATION_DATA*)malloc(sizeof(IOTHUB_AUTHORIZATION_DATA) ); + result = initialize_auth_client(device_id, module_id); if (result == NULL) + { + LogError("Failure initializing auth client"); + } + else if (device_key != NULL && mallocAndStrcpy_s(&result->device_key, device_key) != 0) { /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ - LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA"); + LogError("Failed allocating device_key"); + free(result->device_id); + free(result->module_id); + free(result); result = NULL; } else { - memset(result, 0, sizeof(IOTHUB_AUTHORIZATION_DATA) ); - result->token_expiry_time_sec = DEFAULT_SAS_TOKEN_EXPIRY_TIME_SECS; - - if (device_key != NULL && mallocAndStrcpy_s(&result->device_key, device_key) != 0) - { - /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ - LogError("Failed allocating device_key"); - free(result); - result = NULL; - } - else if (mallocAndStrcpy_s(&result->device_id, device_id) != 0) + if (device_key != NULL) { - /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ - LogError("Failed allocating device_key"); - free(result->device_key); - free(result); - result = NULL; + /* Codes_SRS_IoTHub_Authorization_07_003: [ IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY if the device_sas_token is NULL. ]*/ + result->cred_type = IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY; } - else if (module_id != NULL && mallocAndStrcpy_s(&result->module_id, module_id) != 0) + else if (device_sas_token != NULL) { - /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ - LogError("Failed allocating module_id"); - free(result->device_id); - free(result->device_key); - free(result); - result = NULL; + /* Codes_SRS_IoTHub_Authorization_07_020: [ else IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN. ] */ + result->cred_type = IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN; + if (mallocAndStrcpy_s(&result->device_sas_token, device_sas_token) != 0) + { + /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ + LogError("Failed allocating device_key"); + free(result->device_key); + free(result->device_id); + free(result->module_id); + free(result); + result = NULL; + } } else { - if (device_key != NULL) - { - /* Codes_SRS_IoTHub_Authorization_07_003: [ IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY if the device_sas_token is NULL. ]*/ - result->cred_type = IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY; - } - else if (device_sas_token != NULL) - { - /* Codes_SRS_IoTHub_Authorization_07_020: [ else IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN. ] */ - result->cred_type = IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN; - if (mallocAndStrcpy_s(&result->device_sas_token, device_sas_token) != 0) - { - /* Codes_SRS_IoTHub_Authorization_07_019: [ On error IoTHubClient_Auth_Create shall return NULL. ] */ - LogError("Failed allocating device_key"); - free(result->device_key); - free(result->device_id); - free(result->module_id); - free(result); - result = NULL; - } - } - else - { - /* Codes_SRS_IoTHub_Authorization_07_024: [ if device_sas_token and device_key are NULL IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_UNKNOWN. ] */ - result->cred_type = IOTHUB_CREDENTIAL_TYPE_UNKNOWN; - } + /* Codes_SRS_IoTHub_Authorization_07_024: [ if device_sas_token and device_key are NULL IoTHubClient_Auth_Create shall set the credential type to IOTHUB_CREDENTIAL_TYPE_UNKNOWN. ] */ + result->cred_type = IOTHUB_CREDENTIAL_TYPE_UNKNOWN; } } } @@ -144,35 +159,19 @@ IOTHUB_AUTHORIZATION_HANDLE IoTHubClient_Auth_CreateFromDeviceAuth(const char* d else { #ifdef USE_PROV_MODULE - result = (IOTHUB_AUTHORIZATION_DATA*)malloc(sizeof(IOTHUB_AUTHORIZATION_DATA)); + result = initialize_auth_client(device_id, module_id); if (result == NULL) { - LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA"); - result = NULL; + LogError("Failure initializing auth client"); } else { - memset(result, 0, sizeof(IOTHUB_AUTHORIZATION_DATA)); - result->device_auth_handle = iothub_device_auth_create(); if (result->device_auth_handle == NULL) { LogError("Failed allocating IOTHUB_AUTHORIZATION_DATA"); - free(result); - result = NULL; - } - else if (mallocAndStrcpy_s(&result->device_id, device_id) != 0) - { - LogError("Failed allocating device_id"); - iothub_device_auth_destroy(result->device_auth_handle); - free(result); - result = NULL; - } - else if ((module_id != NULL) && (mallocAndStrcpy_s(&result->module_id, module_id) != 0)) - { - LogError("Failed allocating module_id"); - iothub_device_auth_destroy(result->device_auth_handle); free(result->device_id); + free(result->module_id); free(result); result = NULL; } @@ -606,7 +605,7 @@ static char* read_ca_certificate_from_file(const char* certificate_file_name) LogError("fseek on file %s fails, errno=%d", certificate_file_name, errno); result = NULL; } - else + else { long int file_size = ftell(file_stream); if (file_size < 0) @@ -646,7 +645,7 @@ static char* read_ca_certificate_from_file(const char* certificate_file_name) // IoTHubClient_Auth_Get_TrustBundle retrieves a trust bundle - namely a PEM indicating the certificates the client should // trust as root authorities - to caller. If certificate_file_name, we read this from a local file. This should in general -// be limited only to debugging modules on Edge. If certificate_file_name is NULL, we invoke into the underlying +// be limited only to debugging modules on Edge. If certificate_file_name is NULL, we invoke into the underlying // HSM to retrieve this. char* IoTHubClient_Auth_Get_TrustBundle(IOTHUB_AUTHORIZATION_HANDLE handle, const char* certificate_file_name) { @@ -676,6 +675,12 @@ int IoTHubClient_Auth_Set_SasToken_Expiry(IOTHUB_AUTHORIZATION_HANDLE handle, si LogError("Invalid handle value handle: NULL"); result = __FAILURE__; } + // Validate the expiry_time in seconds + else if (expiry_time_seconds < MIN_SAS_EXPIRY_TIME) + { + LogError("Failure setting expiry time to value %lu min value is %d", (unsigned long)expiry_time_seconds, MIN_SAS_EXPIRY_TIME); + result = __FAILURE__; + } else { handle->token_expiry_time_sec = expiry_time_seconds; diff --git a/iothub_client/src/iothub_client_core.c b/iothub_client/src/iothub_client_core.c index 6b6bc59d12..793cc3a13b 100644 --- a/iothub_client/src/iothub_client_core.c +++ b/iothub_client/src/iothub_client_core.c @@ -1330,6 +1330,10 @@ void IoTHubClientCore_Destroy(IOTHUB_CLIENT_CORE_HANDLE iotHubClientHandle) { free(iotHubClientInstance->method_user_context); } + if (iotHubClientInstance->stream_user_context != NULL) + { + free(iotHubClientInstance->stream_user_context); + } free(iotHubClientInstance); } } @@ -2809,6 +2813,7 @@ IOTHUB_CLIENT_RESULT IoTHubClientCore_SetStreamRequestCallback(IOTHUB_CLIENT_COR if (iotHubClientInstance->stream_user_context == NULL) { LogError("Failed allocating QUEUE_CONTEXT"); + iotHubClientInstance->stream_user_context = previous_user_context; result = IOTHUB_CLIENT_ERROR; } else diff --git a/iothub_client/src/iothub_client_core_ll.c b/iothub_client/src/iothub_client_core_ll.c index af0489c500..7306db13f6 100644 --- a/iothub_client/src/iothub_client_core_ll.c +++ b/iothub_client/src/iothub_client_core_ll.c @@ -331,7 +331,7 @@ static bool is_event_equal_for_match(LIST_ITEM_HANDLE list_item, const void* mat static void device_twin_data_destroy(IOTHUB_DEVICE_TWIN* client_item) { - CONSTBUFFER_Destroy(client_item->report_data_handle); + CONSTBUFFER_DecRef(client_item->report_data_handle); free(client_item); } @@ -1535,6 +1535,11 @@ IOTHUB_CLIENT_CORE_LL_HANDLE IoTHubClientCore_LL_CreateFromConnectionString(cons break; } } + else + { + // If we get an unknown token, log it to error stream but do not cause a fatal error. + LogError("Unknown token <%s> in connection string. Ignoring error and continuing to parse", s_token); + } } } } diff --git a/iothub_client/src/iothub_client_dll.def b/iothub_client/src/iothub_client_dll.def index 89dfb7987c..f6c26b4ce9 100644 --- a/iothub_client/src/iothub_client_dll.def +++ b/iothub_client/src/iothub_client_dll.def @@ -139,6 +139,8 @@ EXPORTS IoTHubMessage_SetInputName IoTHubMessage_SetMessageId IoTHubMessage_SetProperty + IoTHubMessage_SetAsSecurityMessage + IoTHubMessage_IsSecurityMessage IOTHUB_CLIENT_CONFIRMATION_RESULTStrings IOTHUB_CLIENT_FILE_UPLOAD_RESULTStrings diff --git a/iothub_client/src/iothub_message.c b/iothub_client/src/iothub_message.c index 08bef5adc2..0cfa12b6c3 100644 --- a/iothub_client/src/iothub_message.c +++ b/iothub_client/src/iothub_message.c @@ -14,6 +14,7 @@ DEFINE_ENUM_STRINGS(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUE #define LOG_IOTHUB_MESSAGE_ERROR() \ LogError("(result = %s)", ENUM_TO_STRING(IOTHUB_MESSAGE_RESULT, result)); +static const char* SECURITY_CLIENT_JSON_ENCODING = "application/json"; typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG { @@ -34,6 +35,7 @@ typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG char* connectionDeviceId; IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticData; //Deprecated char* distributedTracingTracestate; + bool is_security_message; }IOTHUB_MESSAGE_HANDLE_DATA; static bool ContainsOnlyUsAscii(const char* asciiValue) @@ -105,6 +107,30 @@ static void DestroyMessageData(IOTHUB_MESSAGE_HANDLE_DATA* handleData) free(handleData); } +static int set_content_encoding(IOTHUB_MESSAGE_HANDLE_DATA* handleData, const char* encoding) +{ + int result; + char* tmp_encoding; + + if (mallocAndStrcpy_s(&tmp_encoding, encoding) != 0) + { + LogError("Failed saving a copy of contentEncoding"); + // Codes_SRS_IOTHUBMESSAGE_09_008: [If the allocation or the copying of `contentEncoding` fails, then IoTHubMessage_SetContentEncodingSystemProperty shall return IOTHUB_MESSAGE_ERROR.] + result = __FAILURE__; + } + else + { + // Codes_SRS_IOTHUBMESSAGE_09_007: [If the IOTHUB_MESSAGE_HANDLE `contentEncoding` is not NULL it shall be deallocated.] + if (handleData->contentEncoding != NULL) + { + free(handleData->contentEncoding); + } + handleData->contentEncoding = tmp_encoding; + result = 0; + } + return result; +} + static IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE CloneDiagnosticPropertyData(const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* source) { IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE result = NULL; @@ -282,6 +308,7 @@ IOTHUB_MESSAGE_HANDLE IoTHubMessage_Clone(IOTHUB_MESSAGE_HANDLE iotHubMessageHan { memset(result, 0, sizeof(*result)); result->contentType = source->contentType; + result->is_security_message = source->is_security_message; if (source->messageId != NULL && mallocAndStrcpy_s(&result->messageId, source->messageId) != 0) { @@ -700,16 +727,7 @@ IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentEncodingSystemProperty(IOTHUB_MESS } else { - IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; - - // Codes_SRS_IOTHUBMESSAGE_09_007: [If the IOTHUB_MESSAGE_HANDLE `contentEncoding` is not NULL it shall be deallocated.] - if (handleData->contentEncoding != NULL) - { - free(handleData->contentEncoding); - handleData->contentEncoding = NULL; - } - - if (mallocAndStrcpy_s(&handleData->contentEncoding, contentEncoding) != 0) + if (set_content_encoding(iotHubMessageHandle, contentEncoding) != 0) { LogError("Failed saving a copy of contentEncoding"); // Codes_SRS_IOTHUBMESSAGE_09_008: [If the allocation or the copying of `contentEncoding` fails, then IoTHubMessage_SetContentEncodingSystemProperty shall return IOTHUB_MESSAGE_ERROR.] @@ -721,7 +739,6 @@ IOTHUB_MESSAGE_RESULT IoTHubMessage_SetContentEncodingSystemProperty(IOTHUB_MESS result = IOTHUB_MESSAGE_OK; } } - return result; } @@ -1082,6 +1099,45 @@ IOTHUB_MESSAGE_RESULT IoTHubMessage_SetConnectionDeviceId(IOTHUB_MESSAGE_HANDLE return result; } +IOTHUB_MESSAGE_RESULT IoTHubMessage_SetAsSecurityMessage(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) +{ + IOTHUB_MESSAGE_RESULT result; + if (iotHubMessageHandle == NULL) + { + LogError("Invalid argument (iotHubMessageHandle is NULL)"); + result = IOTHUB_MESSAGE_INVALID_ARG; + } + else + { + iotHubMessageHandle->is_security_message = true; + if (set_content_encoding(iotHubMessageHandle, SECURITY_CLIENT_JSON_ENCODING) != 0) + { + LogError("Failure setting security message content encoding"); + result = IOTHUB_MESSAGE_ERROR; + } + else + { + result = IOTHUB_MESSAGE_OK; + } + } + return result; +} + +bool IoTHubMessage_IsSecurityMessage(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) +{ + bool result; + if (iotHubMessageHandle == NULL) + { + LogError("Invalid argument (iotHubMessageHandle is NULL)"); + result = false; + } + else + { + result = iotHubMessageHandle->is_security_message; + } + return result; +} + void IoTHubMessage_Destroy(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) { /*Codes_SRS_IOTHUBMESSAGE_01_004: [If iotHubMessageHandle is NULL, IoTHubMessage_Destroy shall do nothing.] */ diff --git a/iothub_client/src/iothub_module_client.c b/iothub_client/src/iothub_module_client.c index 5668fa3421..49927e9059 100755 --- a/iothub_client/src/iothub_module_client.c +++ b/iothub_client/src/iothub_module_client.c @@ -127,9 +127,9 @@ IOTHUB_CLIENT_RESULT IoTHubModuleClient_ModuleMethodInvokeAsync(IOTHUB_MODULE_CL return result; } +#endif /*USE_EDGE_MODULES*/ + IOTHUB_CLIENT_RESULT IoTHubModuleClient_SetStreamRequestCallback(IOTHUB_MODULE_CLIENT_HANDLE iotHubModuleClientHandle, DEVICE_STREAM_C2D_REQUEST_CALLBACK streamRequestCallback, void* context) { return IoTHubClientCore_SetStreamRequestCallback((IOTHUB_CLIENT_CORE_HANDLE)iotHubModuleClientHandle, streamRequestCallback, context); } - -#endif /*USE_EDGE_MODULES*/ diff --git a/iothub_client/src/iothubtransport_amqp_common.c b/iothub_client/src/iothubtransport_amqp_common.c index 98ad11a992..b440cde567 100644 --- a/iothub_client/src/iothubtransport_amqp_common.c +++ b/iothub_client/src/iothubtransport_amqp_common.c @@ -314,12 +314,6 @@ static void on_device_state_changed_callback(void* context, DEVICE_STATE previou { registered_device->transport_callbacks.connection_status_cb(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_OK, registered_device->transport_ctx); } - else if (registered_device->transport_instance->state == AMQP_TRANSPORT_STATE_RECONNECTION_REQUIRED || - registered_device->transport_instance->state == AMQP_TRANSPORT_STATE_READY_FOR_RECONNECTION || - registered_device->transport_instance->state == AMQP_TRANSPORT_STATE_RECONNECTING) - { - registered_device->transport_callbacks.connection_status_cb(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_NO_NETWORK, registered_device->transport_ctx); - } } // Codes_SRS_IOTHUBTRANSPORT_AMQP_COMMON_09_122: [If `new_state` is DEVICE_STATE_ERROR_AUTH, IoTHubClientCore_LL_ConnectionStatusCallBack shall be invoked with IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED and IOTHUB_CLIENT_CONNECTION_BAD_CREDENTIAL] else if (new_state == DEVICE_STATE_ERROR_AUTH) @@ -796,7 +790,7 @@ static void on_amqp_connection_state_changed(const void* context, AMQP_CONNECTIO if (new_state == AMQP_CONNECTION_STATE_ERROR) { LogError("Transport received an ERROR from the amqp_connection (state changed %s -> %s); it will be flagged for connection retry.", ENUM_TO_STRING(AMQP_CONNECTION_STATE, previous_state), ENUM_TO_STRING(AMQP_CONNECTION_STATE, new_state)); - + transport_instance->transport_callbacks.connection_status_cb(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_NO_NETWORK, transport_instance->transport_ctx); update_state(transport_instance, AMQP_TRANSPORT_STATE_RECONNECTION_REQUIRED); } else if (new_state == AMQP_CONNECTION_STATE_OPENED) diff --git a/iothub_client/src/iothubtransport_amqp_connection.c b/iothub_client/src/iothubtransport_amqp_connection.c index bf80dd1f73..3c1ec679f3 100644 --- a/iothub_client/src/iothubtransport_amqp_connection.c +++ b/iothub_client/src/iothubtransport_amqp_connection.c @@ -146,11 +146,11 @@ static void on_connection_state_changed(void* context, CONNECTION_STATE new_conn static void on_cbs_open_complete(void* context, CBS_OPEN_COMPLETE_RESULT open_complete_result) { - (void)context; (void)open_complete_result; if (open_complete_result != CBS_OPEN_OK) { LogError("CBS open failed"); + update_state((AMQP_CONNECTION_INSTANCE*)context, AMQP_CONNECTION_STATE_ERROR); } } @@ -158,6 +158,7 @@ static void on_cbs_error(void* context) { (void)context; LogError("CBS Error occured"); + update_state((AMQP_CONNECTION_INSTANCE*)context, AMQP_CONNECTION_STATE_ERROR); } static int create_connection_handle(AMQP_CONNECTION_INSTANCE* instance) @@ -271,7 +272,7 @@ static int create_cbs_handle(AMQP_CONNECTION_INSTANCE* instance) LogError("Failed to create the CBS connection."); } // Codes_SRS_IOTHUBTRANSPORT_AMQP_CONNECTION_09_031: [`instance->cbs_handle` shall be opened using `cbs_open_async`] - else if (cbs_open_async(instance->cbs_handle, on_cbs_open_complete, instance->cbs_handle, on_cbs_error, instance->cbs_handle) != RESULT_OK) + else if (cbs_open_async(instance->cbs_handle, on_cbs_open_complete, instance, on_cbs_error, instance) != RESULT_OK) { // Codes_SRS_IOTHUBTRANSPORT_AMQP_CONNECTION_09_032: [If cbs_open() fails, amqp_connection_create() shall fail and return NULL] result = __FAILURE__; diff --git a/iothub_client/src/iothubtransport_amqp_streaming.c b/iothub_client/src/iothubtransport_amqp_streaming.c index efa31d5a4e..99d524c65d 100644 --- a/iothub_client/src/iothubtransport_amqp_streaming.c +++ b/iothub_client/src/iothubtransport_amqp_streaming.c @@ -899,8 +899,6 @@ static AMQP_MESSENGER_DISPOSITION_RESULT on_amqp_message_received_callback(MESSA { AMQP_MESSENGER_DISPOSITION_RESULT disposition_result; - (void)disposition_info; - // Codes_SRS_IOTHUBTRANSPORT_AMQP_STREAMING_09_048: [If `message` or `context` are NULL, on_amqp_message_received_callback shall return immediately] if (message == NULL || context == NULL) { @@ -912,6 +910,8 @@ static AMQP_MESSENGER_DISPOSITION_RESULT on_amqp_message_received_callback(MESSA AMQP_STREAMING_CLIENT* streaming_client = (AMQP_STREAMING_CLIENT*)context; PARSED_STREAM_INFO parsed_info; + amqp_messenger_destroy_disposition_info(disposition_info); + if (parse_amqp_message(message, &parsed_info) != 0) { LogError("Failed parsing AMQP message"); diff --git a/iothub_client/src/iothubtransport_amqp_twin_messenger.c b/iothub_client/src/iothubtransport_amqp_twin_messenger.c index 9842eed13d..9c9a5c7cea 100644 --- a/iothub_client/src/iothubtransport_amqp_twin_messenger.c +++ b/iothub_client/src/iothubtransport_amqp_twin_messenger.c @@ -1020,7 +1020,7 @@ static bool remove_expired_twin_patch_request(const void* item, const void* matc twin_patch_ctx->on_report_state_complete_callback(TWIN_REPORT_STATE_RESULT_ERROR, TWIN_REPORT_STATE_REASON_TIMEOUT, 0, twin_patch_ctx->on_report_state_complete_context); } - CONSTBUFFER_Destroy(twin_patch_ctx->data); + CONSTBUFFER_DecRef(twin_patch_ctx->data); free(twin_patch_ctx); } else @@ -1181,7 +1181,7 @@ static bool send_pending_twin_patch(const void* item, const void* match_context, } } - CONSTBUFFER_Destroy(twin_patch_ctx->data); + CONSTBUFFER_DecRef(twin_patch_ctx->data); free(twin_patch_ctx); *continue_processing = true; @@ -1308,7 +1308,7 @@ static bool cancel_pending_twin_patch_operation(const void* item, const void* ma twin_patch_ctx->on_report_state_complete_callback(TWIN_REPORT_STATE_RESULT_CANCELLED, TWIN_REPORT_STATE_REASON_MESSENGER_DESTROYED, 0, twin_patch_ctx->on_report_state_complete_context); } - CONSTBUFFER_Destroy(twin_patch_ctx->data); + CONSTBUFFER_DecRef(twin_patch_ctx->data); free(twin_patch_ctx); *continue_processing = true; @@ -1858,44 +1858,42 @@ int twin_messenger_report_state_async(TWIN_MESSENGER_HANDLE twin_msgr_handle, CO LogError("Failed creating context for sending reported state (%s)", twin_msgr->device_id); result = __FAILURE__; } - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_025: [`twin_op_ctx` shall have a copy of `data`] - else if ((twin_patch_ctx->data = CONSTBUFFER_Clone(data)) == NULL) - { - LogError("Failed cloning TWIN patch request data (%s)", twin_msgr->device_id); - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_031: [If any failure occurs, twin_messenger_report_state_async() shall free any memory it has allocated] - free(twin_patch_ctx); - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_026: [If `data` fails to be copied, twin_messenger_report_state_async() shall fail and return a non-zero value] - result = __FAILURE__; - } - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_027: [`twin_op_ctx->time_enqueued` shall be set using get_time] - else if ((twin_patch_ctx->time_enqueued = get_time(NULL)) == INDEFINITE_TIME) - { - LogError("Failed setting reported state enqueue time (%s)", twin_msgr->device_id); - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_031: [If any failure occurs, twin_messenger_report_state_async() shall free any memory it has allocated] - CONSTBUFFER_Destroy(twin_patch_ctx->data); - free(twin_patch_ctx); - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_028: [If `twin_op_ctx->time_enqueued` fails to be set, twin_messenger_report_state_async() shall fail and return a non-zero value] - result = __FAILURE__; - } else { - twin_patch_ctx->on_report_state_complete_callback = on_report_state_complete_callback; - twin_patch_ctx->on_report_state_complete_context = context; + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_025: [`twin_op_ctx` shall increment the reference count for `data` and store it.] + CONSTBUFFER_IncRef(data); + twin_patch_ctx->data = data; - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_029: [`twin_op_ctx` shall be added to `twin_msgr->pending_patches` using singlylinkedlist_add()] - if (singlylinkedlist_add(twin_msgr->pending_patches, twin_patch_ctx) == NULL) + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_027: [`twin_op_ctx->time_enqueued` shall be set using get_time] + if ((twin_patch_ctx->time_enqueued = get_time(NULL)) == INDEFINITE_TIME) { - LogError("Failed adding TWIN patch request to queue (%s)", twin_msgr->device_id); + LogError("Failed setting reported state enqueue time (%s)", twin_msgr->device_id); // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_031: [If any failure occurs, twin_messenger_report_state_async() shall free any memory it has allocated] - CONSTBUFFER_Destroy(twin_patch_ctx->data); + CONSTBUFFER_DecRef(twin_patch_ctx->data); free(twin_patch_ctx); - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_030: [If singlylinkedlist_add() fails, twin_messenger_report_state_async() shall fail and return a non-zero value] + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_028: [If `twin_op_ctx->time_enqueued` fails to be set, twin_messenger_report_state_async() shall fail and return a non-zero value] result = __FAILURE__; } else { - // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_032: [If no failures occur, twin_messenger_report_state_async() shall return zero] - result = RESULT_OK; + twin_patch_ctx->on_report_state_complete_callback = on_report_state_complete_callback; + twin_patch_ctx->on_report_state_complete_context = context; + + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_029: [`twin_op_ctx` shall be added to `twin_msgr->pending_patches` using singlylinkedlist_add()] + if (singlylinkedlist_add(twin_msgr->pending_patches, twin_patch_ctx) == NULL) + { + LogError("Failed adding TWIN patch request to queue (%s)", twin_msgr->device_id); + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_031: [If any failure occurs, twin_messenger_report_state_async() shall free any memory it has allocated] + CONSTBUFFER_DecRef(twin_patch_ctx->data); + free(twin_patch_ctx); + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_030: [If singlylinkedlist_add() fails, twin_messenger_report_state_async() shall fail and return a non-zero value] + result = __FAILURE__; + } + else + { + // Codes_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_032: [If no failures occur, twin_messenger_report_state_async() shall return zero] + result = RESULT_OK; + } } } } diff --git a/iothub_client/src/iothubtransport_mqtt_common.c b/iothub_client/src/iothubtransport_mqtt_common.c index b3149a92be..836414880b 100755 --- a/iothub_client/src/iothubtransport_mqtt_common.c +++ b/iothub_client/src/iothubtransport_mqtt_common.c @@ -27,6 +27,7 @@ #include "iothub_client_streaming.h" #include "internal/iothubtransport_mqtt_common.h" #include "internal/iothubtransport.h" +#include "internal/iothub_internal_consts.h" #include "azure_umqtt_c/mqtt_client.h" @@ -89,8 +90,6 @@ static const char* STREAM_PROPERTY_AUTH = "$auth"; #define MIN_DEVICE_STREAMING_NUM_OF_PARAMETERS 4 #define MAX_DEVICE_STREAMING_NUM_OF_PARAMETERS 5 -static const char* IOTHUB_API_VERSION = "2017-11-08-preview"; - static const char* PROPERTY_SEPARATOR = "&"; static const char* REPORTED_PROPERTIES_TOPIC = "$iothub/twin/PATCH/properties/reported/?$rid=%"PRIu16; static const char* GET_PROPERTIES_TOPIC = "$iothub/twin/GET/?$rid=%"PRIu16; @@ -216,6 +215,7 @@ typedef struct MQTTTRANSPORT_HANDLE_DATA_TAG bool isRegistered; MQTT_CLIENT_STATUS mqttClientStatus; bool isDestroyCalled; + bool isRetryExpiredCallbackSet; bool device_twin_get_sent; bool twin_resp_sub_recv; bool isRecoverableError; @@ -711,10 +711,10 @@ static int addSystemPropertyToTopicString(STRING_HANDLE topic_string, size_t ind static int addSystemPropertiesTouMqttMessage(IOTHUB_MESSAGE_HANDLE iothub_message_handle, STRING_HANDLE topic_string, size_t* index_ptr, bool urlencode) { - (void)urlencode; int result = 0; size_t index = *index_ptr; + bool is_security_msg = IoTHubMessage_IsSecurityMessage(iothub_message_handle); /* Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_07_052: [ IoTHubTransport_MQTT_Common_DoWork shall check for the CorrelationId property and if found add the value as a system property in the format of $.cid= ] */ const char* correlation_id = IoTHubMessage_GetCorrelationId(iothub_message_handle); if (correlation_id != NULL) @@ -748,7 +748,8 @@ static int addSystemPropertiesTouMqttMessage(IOTHUB_MESSAGE_HANDLE iothub_messag const char* content_encoding = IoTHubMessage_GetContentEncodingSystemProperty(iothub_message_handle); if (content_encoding != NULL) { - result = addSystemPropertyToTopicString(topic_string, index, CONTENT_ENCODING_PROPERTY, content_encoding, urlencode); + // Security message require content encoding + result = addSystemPropertyToTopicString(topic_string, index, CONTENT_ENCODING_PROPERTY, content_encoding, is_security_msg ? true : urlencode); index++; } } @@ -762,6 +763,22 @@ static int addSystemPropertiesTouMqttMessage(IOTHUB_MESSAGE_HANDLE iothub_messag index++; } } + if (result == 0) + { + if (is_security_msg) + { + // The Security interface Id value must be encoded + if (addSystemPropertyToTopicString(topic_string, index++, SECURITY_INTERFACE_ID_MQTT, SECURITY_INTERFACE_ID_VALUE, true) != 0) + { + LogError("Failed setting Security interface id"); + result = __FAILURE__; + } + else + { + result = 0; + } + } + } *index_ptr = index; return result; } @@ -863,7 +880,7 @@ static STRING_HANDLE addPropertiesTouMqttMessage(IOTHUB_MESSAGE_HANDLE iothub_me result = NULL; } - // Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_31_060: [ `IoTHubTransport_MQTT_Common_DoWork` shall check for the OutputName property and if found add the alue as a system property in the format of $.on= ] + // Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_31_060: [ `IoTHubTransport_MQTT_Common_DoWork` shall check for the OutputName property and if found add the value as a system property in the format of $.on= ] if (result != NULL) { const char* output_name = IoTHubMessage_GetOutputName(iothub_message_handle); @@ -972,7 +989,7 @@ static void destroy_device_twin_get_message(MQTT_DEVICE_TWIN_ITEM* msg_entry) static MQTT_DEVICE_TWIN_ITEM* create_device_twin_get_message(MQTTTRANSPORT_HANDLE_DATA* transport_data) { MQTT_DEVICE_TWIN_ITEM* result; - + if ((result = (MQTT_DEVICE_TWIN_ITEM*)malloc(sizeof(MQTT_DEVICE_TWIN_ITEM))) == NULL) { LogError("Failed allocating device twin data."); @@ -2705,6 +2722,7 @@ static int SendMqttConnectMsg(PMQTTTRANSPORT_HANDLE_DATA transport_data) else { transport_data->currPacketState = CONNECT_TYPE; + transport_data->isRetryExpiredCallbackSet = false; (void)tickcounter_get_current_ms(transport_data->msgTickCounter, &transport_data->mqtt_connect_time); result = 0; } @@ -2735,31 +2753,46 @@ static int InitializeConnection(PMQTTTRANSPORT_HANDLE_DATA transport_data) RETRY_ACTION retry_action = RETRY_ACTION_RETRY_LATER; // Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_09_007: [ IoTHubTransport_MQTT_Common_DoWork shall try to reconnect according to the current retry policy set ] - if (transport_data->mqttClientStatus == MQTT_CLIENT_STATUS_NOT_CONNECTED && transport_data->isRecoverableError && - (retry_control_should_retry(transport_data->retry_control_handle, &retry_action) != 0 || retry_action == RETRY_ACTION_RETRY_NOW)) + if (transport_data->mqttClientStatus == MQTT_CLIENT_STATUS_NOT_CONNECTED && transport_data->isRecoverableError) { // Note: in case retry_control_should_retry fails, the reconnection shall be attempted anyway (defaulting to policy IOTHUB_CLIENT_RETRY_IMMEDIATE). - - if (tickcounter_get_current_ms(transport_data->msgTickCounter, &transport_data->connectTick) != 0) + if (retry_control_should_retry(transport_data->retry_control_handle, &retry_action) != 0 || retry_action == RETRY_ACTION_RETRY_NOW) { - transport_data->connectFailCount++; - result = __FAILURE__; - } - else - { - ResetConnectionIfNecessary(transport_data); - - if (SendMqttConnectMsg(transport_data) != 0) + if (tickcounter_get_current_ms(transport_data->msgTickCounter, &transport_data->connectTick) != 0) { transport_data->connectFailCount++; result = __FAILURE__; } else { - transport_data->mqttClientStatus = MQTT_CLIENT_STATUS_CONNECTING; - transport_data->connectFailCount = 0; - result = 0; + ResetConnectionIfNecessary(transport_data); + + if (SendMqttConnectMsg(transport_data) != 0) + { + transport_data->connectFailCount++; + result = __FAILURE__; + } + else + { + transport_data->mqttClientStatus = MQTT_CLIENT_STATUS_CONNECTING; + transport_data->connectFailCount = 0; + result = 0; + } + } + } + else if (retry_action == RETRY_ACTION_STOP_RETRYING) + { + // Set callback if retry expired + if (!transport_data->isRetryExpiredCallbackSet) + { + transport_data->transport_callbacks.connection_status_cb(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_RETRY_EXPIRED, transport_data->transport_ctx); + transport_data->isRetryExpiredCallbackSet = true; } + result = __FAILURE__; + } + else if (retry_action == RETRY_ACTION_RETRY_LATER) + { + result = __FAILURE__; } } else if (transport_data->mqttClientStatus == MQTT_CLIENT_STATUS_EXECUTE_DISCONNECT) @@ -2796,41 +2829,46 @@ static int InitializeConnection(PMQTTTRANSPORT_HANDLE_DATA transport_data) } else { - size_t sas_token_expiry = IoTHubClient_Auth_Get_SasToken_Expiry(transport_data->authorization_module); - if ((current_time - transport_data->mqtt_connect_time) / 1000 > (sas_token_expiry*SAS_REFRESH_MULTIPLIER)) + IOTHUB_CREDENTIAL_TYPE cred_type = IoTHubClient_Auth_Get_Credential_Type(transport_data->authorization_module); + // If the credential type is not an x509 certificate then we shall renew the Sas_Token + if (cred_type != IOTHUB_CREDENTIAL_TYPE_X509 && cred_type != IOTHUB_CREDENTIAL_TYPE_X509_ECC) { - /* Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_07_058: [ If the sas token has timed out IoTHubTransport_MQTT_Common_DoWork shall disconnect from the mqtt client and destroy the transport information and wait for reconnect. ] */ - DisconnectFromClient(transport_data); - - transport_data->transport_callbacks.connection_status_cb(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_EXPIRED_SAS_TOKEN, transport_data->transport_ctx); - transport_data->currPacketState = UNKNOWN_TYPE; - if (transport_data->topic_MqttMessage != NULL) - { - transport_data->topics_ToSubscribe |= SUBSCRIBE_TELEMETRY_TOPIC; - } - if (transport_data->topic_GetState != NULL) + size_t sas_token_expiry = IoTHubClient_Auth_Get_SasToken_Expiry(transport_data->authorization_module); + if ((current_time - transport_data->mqtt_connect_time) / 1000 > (sas_token_expiry*SAS_REFRESH_MULTIPLIER)) { - transport_data->topics_ToSubscribe |= SUBSCRIBE_GET_REPORTED_STATE_TOPIC; - } - if (transport_data->topic_NotifyState != NULL) - { - transport_data->topics_ToSubscribe |= SUBSCRIBE_NOTIFICATION_STATE_TOPIC; - } - if (transport_data->topic_DeviceMethods != NULL) - { - transport_data->topics_ToSubscribe |= SUBSCRIBE_DEVICE_METHOD_TOPIC; - } - if (transport_data->topic_InputQueue != NULL) - { - transport_data->topics_ToSubscribe |= SUBSCRIBE_INPUT_QUEUE_TOPIC; - } - if (transport_data->topic_StreamsPost != NULL) - { - transport_data->topics_ToSubscribe |= SUBSCRIBE_STREAMS_POST_TOPIC; - } - if (transport_data->topic_StreamsResp != NULL) - { - transport_data->topics_ToSubscribe |= SUBSCRIBE_STREAMS_RESP_TOPIC; + /* Codes_SRS_IOTHUB_TRANSPORT_MQTT_COMMON_07_058: [ If the sas token has timed out IoTHubTransport_MQTT_Common_DoWork shall disconnect from the mqtt client and destroy the transport information and wait for reconnect. ] */ + DisconnectFromClient(transport_data); + + transport_data->transport_callbacks.connection_status_cb(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_EXPIRED_SAS_TOKEN, transport_data->transport_ctx); + transport_data->currPacketState = UNKNOWN_TYPE; + if (transport_data->topic_MqttMessage != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_TELEMETRY_TOPIC; + } + if (transport_data->topic_GetState != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_GET_REPORTED_STATE_TOPIC; + } + if (transport_data->topic_NotifyState != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_NOTIFICATION_STATE_TOPIC; + } + if (transport_data->topic_DeviceMethods != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_DEVICE_METHOD_TOPIC; + } + if (transport_data->topic_InputQueue != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_INPUT_QUEUE_TOPIC; + } + if (transport_data->topic_StreamsPost != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_STREAMS_POST_TOPIC; + } + if (transport_data->topic_StreamsResp != NULL) + { + transport_data->topics_ToSubscribe |= SUBSCRIBE_STREAMS_RESP_TOPIC; + } } } } @@ -2974,6 +3012,7 @@ static PMQTTTRANSPORT_HANDLE_DATA InitializeTransportHandleData(const IOTHUB_CLI state->authorization_module = auth_module; state->isDestroyCalled = false; + state->isRetryExpiredCallbackSet = false; state->isRegistered = false; state->device_twin_get_sent = false; state->xioTransport = NULL; diff --git a/iothub_client/src/iothubtransporthttp.c b/iothub_client/src/iothubtransporthttp.c index 33226421df..bd94ed0ea1 100755 --- a/iothub_client/src/iothubtransporthttp.c +++ b/iothub_client/src/iothubtransporthttp.c @@ -13,6 +13,7 @@ #include "internal/iothub_client_private.h" #include "internal/iothubtransport.h" #include "internal/iothub_transport_ll_private.h" +#include "internal/iothub_internal_consts.h" #include "azure_c_shared_utility/optimize_size.h" #include "azure_c_shared_utility/httpapiexsas.h" @@ -21,7 +22,7 @@ #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/doublylinkedlist.h" #include "azure_c_shared_utility/vector.h" #include "azure_c_shared_utility/httpheaders.h" @@ -35,6 +36,8 @@ static const char* IOTHUB_CONTENT_ENCODING_D2C = "iothub-contentencoding"; static const char* IOTHUB_CONTENT_TYPE_C2D = "ContentType"; static const char* IOTHUB_CONTENT_ENCODING_C2D = "ContentEncoding"; +static const char* IOTHUB_AUTH_HEADER_VALUE = "Authorization"; + #define CONTENT_TYPE "Content-Type" #define APPLICATION_OCTET_STREAM "application/octet-stream" #define APPLICATION_VND_MICROSOFT_IOTHUB_JSON "application/vnd.microsoft.iothub.json" @@ -137,6 +140,213 @@ static bool create_eventHTTPrelativePath(HTTPTRANSPORT_PERDEVICE_DATA* handleDat return result; } +static int retrieve_message_properties(HTTP_HEADERS_HANDLE resp_header, IOTHUB_MESSAGE_HANDLE recv_msg) +{ + int result = 0; + /*Codes_SRS_TRANSPORTMULTITHTTP_17_090: [All the HTTP headers of the form iothub-app-name:somecontent shall be transformed in message properties {name, somecontent}.]*/ + /*Codes_SRS_TRANSPORTMULTITHTTP_17_091: [The HTTP header of iothub-messageid shall be set in the MessageId.]*/ + size_t nHeaders; + if (HTTPHeaders_GetHeaderCount(resp_header, &nHeaders) != HTTP_HEADERS_OK) + { + LogError("unable to get the count of HTTP headers"); + result = __FAILURE__; + } + else + { + MAP_HANDLE properties = (nHeaders > 0) ? IoTHubMessage_Properties(recv_msg) : NULL; + for (size_t index = 0; index < nHeaders; index++) + { + char* completeHeader; + if (HTTPHeaders_GetHeader(resp_header, index, &completeHeader) != HTTP_HEADERS_OK) + { + LogError("Failed getting header %lu", (unsigned long)index); + result = __FAILURE__; + break; + } + else + { + char* colon_pos; + if (strncmp(IOTHUB_APP_PREFIX, completeHeader, strlen(IOTHUB_APP_PREFIX)) == 0) + { + /*looks like a property headers*/ + /*there's a guaranteed ':' in the completeHeader, by HTTP_HEADERS module*/ + colon_pos = strchr(completeHeader, ':'); + if (colon_pos != NULL) + { + *colon_pos = '\0'; /*cut it down*/ + if (Map_AddOrUpdate(properties, completeHeader + strlen(IOTHUB_APP_PREFIX), colon_pos + 2) != MAP_OK) /*whereIsColon+1 is a space because HTTPEHADERS outputs a ": " between name and value*/ + { + free(completeHeader); + result = __FAILURE__; + break; + } + } + } + else if (strncmp(IOTHUB_MESSAGE_ID, completeHeader, strlen(IOTHUB_MESSAGE_ID)) == 0) + { + char* whereIsColon = strchr(completeHeader, ':'); + if (whereIsColon != NULL) + { + *whereIsColon = '\0'; /*cut it down*/ + if (IoTHubMessage_SetMessageId(recv_msg, whereIsColon + 2) != IOTHUB_MESSAGE_OK) + { + free(completeHeader); + result = __FAILURE__; + break; + } + } + } + else if (strncmp(IOTHUB_CORRELATION_ID, completeHeader, strlen(IOTHUB_CORRELATION_ID)) == 0) + { + char* whereIsColon = strchr(completeHeader, ':'); + if (whereIsColon != NULL) + { + *whereIsColon = '\0'; /*cut it down*/ + if (IoTHubMessage_SetCorrelationId(recv_msg, whereIsColon + 2) != IOTHUB_MESSAGE_OK) + { + free(completeHeader); + result = __FAILURE__; + break; + } + } + } + // Codes_SRS_TRANSPORTMULTITHTTP_09_003: [ The HTTP header value of `ContentType` shall be set in the `IoTHubMessage_SetContentTypeSystemProperty`. ] + else if (strncmp(IOTHUB_CONTENT_TYPE_C2D, completeHeader, strlen(IOTHUB_CONTENT_TYPE_C2D)) == 0) + { + char* whereIsColon = strchr(completeHeader, ':'); + if (whereIsColon != NULL) + { + *whereIsColon = '\0'; /*cut it down*/ + if (IoTHubMessage_SetContentTypeSystemProperty(recv_msg, whereIsColon + 2) != IOTHUB_MESSAGE_OK) + { + LogError("Failed setting IoTHubMessage content-type"); + result = __FAILURE__; + break; + } + } + } + // Codes_SRS_TRANSPORTMULTITHTTP_09_004: [ The HTTP header value of `ContentEncoding` shall be set in the `IoTHub_SetContentEncoding`. ] + else if (strncmp(IOTHUB_CONTENT_ENCODING_C2D, completeHeader, strlen(IOTHUB_CONTENT_ENCODING_C2D)) == 0) + { + char* whereIsColon = strchr(completeHeader, ':'); + if (whereIsColon != NULL) + { + *whereIsColon = '\0'; /*cut it down*/ + if (IoTHubMessage_SetContentEncodingSystemProperty(recv_msg, whereIsColon + 2) != IOTHUB_MESSAGE_OK) + { + LogError("Failed setting IoTHubMessage content-encoding"); + break; + } + } + } + free(completeHeader); + } + } + } + return result; +} + +static int set_system_properties(IOTHUB_MESSAGE_LIST* message, HTTP_HEADERS_HANDLE headers) +{ + int result; + const char* msgId; + const char* corrId; + const char* content_type; + const char* contentEncoding; + + // Add the Message Id and the Correlation Id + msgId = IoTHubMessage_GetMessageId(message->messageHandle); + if (msgId != NULL && HTTPHeaders_ReplaceHeaderNameValuePair(headers, IOTHUB_MESSAGE_ID, msgId) != HTTP_HEADERS_OK) + { + LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair"); + result = __LINE__; + } + else if ((corrId = IoTHubMessage_GetCorrelationId(message->messageHandle)) != NULL && HTTPHeaders_ReplaceHeaderNameValuePair(headers, IOTHUB_CORRELATION_ID, corrId) != HTTP_HEADERS_OK) + { + LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair"); + result = __LINE__; + } + // Codes_SRS_TRANSPORTMULTITHTTP_09_001: [ If the IoTHubMessage being sent contains property `content-type` it shall be added to the HTTP headers as "iothub-contenttype":"value". ] + else if ((content_type = IoTHubMessage_GetContentTypeSystemProperty(message->messageHandle)) != NULL && HTTPHeaders_ReplaceHeaderNameValuePair(headers, IOTHUB_CONTENT_TYPE_D2C, content_type) != HTTP_HEADERS_OK) + { + LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-type)"); + result = __LINE__; + } + // Codes_SRS_TRANSPORTMULTITHTTP_09_002: [ If the IoTHubMessage being sent contains property `content-encoding` it shall be added to the HTTP headers as "iothub-contentencoding":"value". ] + else if ((contentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message->messageHandle)) != NULL && HTTPHeaders_ReplaceHeaderNameValuePair(headers, IOTHUB_CONTENT_ENCODING_D2C, contentEncoding) != HTTP_HEADERS_OK) + { + LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-encoding)"); + result = __LINE__; + } + else if (IoTHubMessage_IsSecurityMessage(message->messageHandle) && HTTPHeaders_ReplaceHeaderNameValuePair(headers, SECURITY_INTERFACE_ID, SECURITY_INTERFACE_ID_VALUE) != HTTP_HEADERS_OK) + { + LogError("unable to set security message header info"); + result = __LINE__; + } + else + { + result = 0; + } + return result; +} + +static bool set_message_properties(IOTHUB_MESSAGE_LIST* message, size_t* msg_size, HTTP_HEADERS_HANDLE headers, HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERDEVICE_DATA* deviceData) +{ + bool result = true; + + /*Codes_SRS_TRANSPORTMULTITHTTP_17_078: [Every message property "property":"value" shall be added to the HTTP headers as an individual header "iothub-app-property":"value".] */ + MAP_HANDLE map = IoTHubMessage_Properties(message->messageHandle); + const char*const* keys; + const char*const* values; + size_t count; + if (Map_GetInternals(map, &keys, &values, &count) != MAP_OK) + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ + LogError("unable to Map_GetInternals"); + result = false; + } + else + { + for (size_t index = 0; index < count; index++) + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_074: [Every property name shall add to the message size the length of the property name + the length of the property value + 16 bytes.] */ + *msg_size += (strlen(values[index]) + strlen(keys[index]) + MAXIMUM_PROPERTY_OVERHEAD); + if (*msg_size > MAXIMUM_MESSAGE_SIZE) + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_072: [The message size shall be limited to 255KB -1 bytes.] */ + PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/ + DList_InsertTailList(&(deviceData->eventConfirmations), head); + handleData->transport_callbacks.send_complete_cb(&(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR, deviceData->device_transport_ctx); // takes care of emptying the list too + result = false; + break; + } + else + { + STRING_HANDLE app_construct = STRING_construct_sprintf("%s%s", IOTHUB_APP_PREFIX, keys[index]); + if (app_construct == NULL) + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ + LogError("Unable to construct app header"); + result = false; + break; + } + else + { + if (HTTPHeaders_ReplaceHeaderNameValuePair(headers, STRING_c_str(app_construct), values[index]) != HTTP_HEADERS_OK) + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ + LogError("Unable to add app properties to http header"); + result = false; + break; + } + STRING_delete(app_construct); + } + } + } + } + return result; +} + static void destroy_messageHTTPrelativePath(HTTPTRANSPORT_PERDEVICE_DATA* handleData) { STRING_delete(handleData->messageHTTPrelativePath); @@ -236,7 +446,7 @@ static bool create_eventHTTPrequestHeaders(HTTPTRANSPORT_PERDEVICE_DATA* handleD { if (!( (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "iothub-to", STRING_c_str(temp)) == HTTP_HEADERS_OK) && - (is_x509_used || (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "Authorization", " ") == HTTP_HEADERS_OK)) && + (is_x509_used || (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, IOTHUB_AUTH_HEADER_VALUE, " ") == HTTP_HEADERS_OK)) && (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "Accept", "application/json") == HTTP_HEADERS_OK) && (HTTPHeaders_AddHeaderNameValuePair(handleData->eventHTTPrequestHeaders, "Connection", "Keep-Alive") == HTTP_HEADERS_OK) && (addUserAgentHeaderInfo(transport_data, handleData->eventHTTPrequestHeaders) == HTTP_HEADERS_OK) @@ -280,7 +490,7 @@ static bool create_messageHTTPrequestHeaders(HTTPTRANSPORT_PERDEVICE_DATA* handl { if (!( (addUserAgentHeaderInfo(transport_data, handleData->messageHTTPrequestHeaders) == HTTP_HEADERS_OK) && - (is_x509_used || (HTTPHeaders_AddHeaderNameValuePair(handleData->messageHTTPrequestHeaders, "Authorization", " ") == HTTP_HEADERS_OK)) + (is_x509_used || (HTTPHeaders_AddHeaderNameValuePair(handleData->messageHTTPrequestHeaders, IOTHUB_AUTH_HEADER_VALUE, " ") == HTTP_HEADERS_OK)) )) { /*Codes_SRS_TRANSPORTMULTITHTTP_17_023: [ If creating message HTTP request headers then IoTHubTransportHttp_Register shall fail and return NULL. ]*/ @@ -1145,10 +1355,10 @@ static STRING_HANDLE make1EventJSONitem(PDLIST_ENTRY item, size_t *messageSizeCo } else { - STRING_HANDLE encoded = Base64_Encode_Bytes(source, size); + STRING_HANDLE encoded = Azure_Base64_Encode_Bytes(source, size); if (encoded == NULL) { - LogError("unable to Base64_Encode_Bytes."); + LogError("unable to Azure_Base64_Encode_Bytes."); STRING_delete(result); result = NULL; } @@ -1541,199 +1751,76 @@ static void DoEvent(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERDEVI } else { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_078: [Every message property "property":"value" shall be added to the HTTP headers as an individual header "iothub-app-property":"value".] */ - MAP_HANDLE map = IoTHubMessage_Properties(message->messageHandle); - const char*const* keys; - const char*const* values; - size_t count; - if (Map_GetInternals(map, &keys, &values, &count) != MAP_OK) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ - LogError("unable to Map_GetInternals"); - } - else + // set_message_properties returning false does not necessarily mean the the function failed, it just means + // the the adding of messages should not continue and should try the next time. So you should not log if this + // returns false + if (set_message_properties(message, &messageSize, clonedEventHTTPrequestHeaders, handleData, deviceData)) { - size_t i; - bool goOn = true; - const char* msgId; - const char* corrId; - const char* userDefinedContentType; - const char* contentEncoding; - - for (i = 0; (i < count) && goOn; i++) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_074: [Every property name shall add to the message size the length of the property name + the length of the property value + 16 bytes.] */ - messageSize += (strlen(values[i]) + strlen(keys[i]) + MAXIMUM_PROPERTY_OVERHEAD); - if (messageSize > MAXIMUM_MESSAGE_SIZE) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_072: [The message size shall be limited to 255KB -1 bytes.] */ - PDLIST_ENTRY head = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/ - DList_InsertTailList(&(deviceData->eventConfirmations), head); - handleData->transport_callbacks.send_complete_cb(&(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR, deviceData->device_transport_ctx); // takes care of emptying the list too - goOn = false; - } - else - { - STRING_HANDLE temp = STRING_construct(IOTHUB_APP_PREFIX); - if (temp == NULL) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ - LogError("unable to STRING_construct"); - goOn = false; - } - else - { - if (STRING_concat(temp, keys[i]) != 0) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ - LogError("unable to STRING_concat"); - goOn = false; - } - else - { - if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, STRING_c_str(temp), values[i]) != HTTP_HEADERS_OK) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ - LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair"); - goOn = false; - } - } - STRING_delete(temp); - } - } - } - - // Add the Message Id and the Correlation Id - msgId = IoTHubMessage_GetMessageId(message->messageHandle); - if (goOn && msgId != NULL) - { - if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_MESSAGE_ID, msgId) != HTTP_HEADERS_OK) - { - LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair"); - goOn = false; - } - } - - corrId = IoTHubMessage_GetCorrelationId(message->messageHandle); - if (goOn && corrId != NULL) - { - if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CORRELATION_ID, corrId) != HTTP_HEADERS_OK) - { - LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair"); - goOn = false; - } - } - - // Codes_SRS_TRANSPORTMULTITHTTP_09_001: [ If the IoTHubMessage being sent contains property `content-type` it shall be added to the HTTP headers as "iothub-contenttype":"value". ] - userDefinedContentType = IoTHubMessage_GetContentTypeSystemProperty(message->messageHandle); - if (goOn && userDefinedContentType != NULL) - { - if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CONTENT_TYPE_D2C, userDefinedContentType) != HTTP_HEADERS_OK) - { - LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-type)"); - goOn = false; - } - } - - // Codes_SRS_TRANSPORTMULTITHTTP_09_002: [ If the IoTHubMessage being sent contains property `content-encoding` it shall be added to the HTTP headers as "iothub-contentencoding":"value". ] - contentEncoding = IoTHubMessage_GetContentEncodingSystemProperty(message->messageHandle); - if (goOn && contentEncoding != NULL) - { - if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_CONTENT_ENCODING_D2C, contentEncoding) != HTTP_HEADERS_OK) - { - LogError("unable to HTTPHeaders_ReplaceHeaderNameValuePair (content-encoding)"); - goOn = false; - } - } - if (!goOn) + if (set_system_properties(message, clonedEventHTTPrequestHeaders) != 0) { /*Codes_SRS_TRANSPORTMULTITHTTP_17_079: [If any HTTP header operation fails, _DoWork shall advance to the next action.] */ } else { - BUFFER_HANDLE toBeSend = BUFFER_new(); + BUFFER_HANDLE toBeSend = BUFFER_create(messageContent, originalMessageSize); if (toBeSend == NULL) { LogError("unable to BUFFER_new"); } else { - if (BUFFER_build(toBeSend, messageContent, originalMessageSize) != 0) - { - LogError("unable to BUFFER_build"); - } - else + unsigned int statusCode = 0; + HTTPAPIEX_RESULT r; + if (deviceData->deviceSasToken != NULL) { - unsigned int statusCode = 0; - HTTPAPIEX_RESULT r; - if (deviceData->deviceSasToken != NULL) + /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/ + if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, IOTHUB_AUTH_HEADER_VALUE, STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK) { - /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/ - if (HTTPHeaders_ReplaceHeaderNameValuePair(clonedEventHTTPrequestHeaders, "Authorization", STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK) - { - r = HTTPAPIEX_ERROR; - /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/ - LogError("Unable to replace the old SAS Token."); - } - - /*Codes_SRS_TRANSPORTMULTITHTTP_03_003: [If a deviceSasToken exists, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_ExecuteRequest passing the following parameters] */ - else if ((r = HTTPAPIEX_ExecuteRequest( - handleData->httpApiExHandle, - HTTPAPI_REQUEST_POST, - STRING_c_str(deviceData->eventHTTPrelativePath), - clonedEventHTTPrequestHeaders, - toBeSend, - &statusCode, - NULL, - NULL - )) != HTTPAPIEX_OK) - { - LogError("Unable to HTTPAPIEX_ExecuteRequest."); - } + r = HTTPAPIEX_ERROR; + /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/ + LogError("Unable to replace the old SAS Token."); } - else + /*Codes_SRS_TRANSPORTMULTITHTTP_03_003: [If a deviceSasToken exists, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_ExecuteRequest passing the following parameters] */ + else if ((r = HTTPAPIEX_ExecuteRequest( + handleData->httpApiExHandle, HTTPAPI_REQUEST_POST, STRING_c_str(deviceData->eventHTTPrelativePath), + clonedEventHTTPrequestHeaders, toBeSend, &statusCode, NULL, NULL)) != HTTPAPIEX_OK) { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_080: [If a deviceSasToken does not exist, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest passing the following parameters] */ - if ((r = HTTPAPIEX_SAS_ExecuteRequest( - deviceData->sasObject, - handleData->httpApiExHandle, - HTTPAPI_REQUEST_POST, - STRING_c_str(deviceData->eventHTTPrelativePath), - clonedEventHTTPrequestHeaders, - toBeSend, - &statusCode, - NULL, - NULL - )) != HTTPAPIEX_OK) - { - LogError("unable to HTTPAPIEX_SAS_ExecuteRequest"); - } + LogError("Unable to HTTPAPIEX_ExecuteRequest."); } - if (r == HTTPAPIEX_OK) + } + else + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_080: [If a deviceSasToken does not exist, IoTHubTransportHttp_DoWork shall call HTTPAPIEX_SAS_ExecuteRequest passing the following parameters] */ + if ((r = HTTPAPIEX_SAS_ExecuteRequest(deviceData->sasObject, handleData->httpApiExHandle, HTTPAPI_REQUEST_POST, STRING_c_str(deviceData->eventHTTPrelativePath), + clonedEventHTTPrequestHeaders, toBeSend, &statusCode, NULL, NULL )) != HTTPAPIEX_OK) { - if (statusCode < 300) - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_082: [If HTTPAPIEX_SAS_ExecuteRequest does not fail and http status code <300 then IoTHubTransportHttp_DoWork shall call IoTHubClientCore_LL_SendComplete. Parameter PDLIST_ENTRY completed shall point to a list the item send, and parameter IOTHUB_CLIENT_CONFIRMATION_RESULT result shall be set to IOTHUB_CLIENT_CONFIRMATION_OK. The item shall be removed from waitingToSend.] */ - PDLIST_ENTRY justSent = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/ - DList_InsertTailList(&(deviceData->eventConfirmations), justSent); - handleData->transport_callbacks.send_complete_cb(&(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_OK, deviceData->device_transport_ctx); // takes care of emptying the list too - } - else - { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_081: [If HTTPAPIEX_SAS_ExecuteRequest fails or the http status code >=300 then IoTHubTransportHttp_DoWork shall not do any other action (it is assumed at the next _DoWork it shall be retried).] */ - LogError("unexpected HTTP status code (%u)", statusCode); - } + LogError("unable to HTTPAPIEX_SAS_ExecuteRequest"); } - else if (r == HTTPAPIEX_RECOVERYFAILED) + } + if (r == HTTPAPIEX_OK) + { + if (statusCode < 300) { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_082: [If HTTPAPIEX_SAS_ExecuteRequest does not fail and http status code <300 then IoTHubTransportHttp_DoWork shall call IoTHubClientCore_LL_SendComplete. Parameter PDLIST_ENTRY completed shall point to a list the item send, and parameter IOTHUB_CLIENT_CONFIRMATION_RESULT result shall be set to IOTHUB_CLIENT_CONFIRMATION_OK. The item shall be removed from waitingToSend.] */ PDLIST_ENTRY justSent = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/ DList_InsertTailList(&(deviceData->eventConfirmations), justSent); - handleData->transport_callbacks.send_complete_cb(&(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR, deviceData->device_transport_ctx); // takes care of emptying the list too + handleData->transport_callbacks.send_complete_cb(&(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_OK, deviceData->device_transport_ctx); // takes care of emptying the list too + } + else + { + /*Codes_SRS_TRANSPORTMULTITHTTP_17_081: [If HTTPAPIEX_SAS_ExecuteRequest fails or the http status code >=300 then IoTHubTransportHttp_DoWork shall not do any other action (it is assumed at the next _DoWork it shall be retried).] */ + LogError("unexpected HTTP status code (%u)", statusCode); } } - BUFFER_delete(toBeSend); + else if (r == HTTPAPIEX_RECOVERYFAILED) + { + PDLIST_ENTRY justSent = DList_RemoveHeadList(deviceData->waitingToSend); /*actually this is the same as "actual", but now it is removed*/ + DList_InsertTailList(&(deviceData->eventConfirmations), justSent); + handleData->transport_callbacks.send_complete_cb(&(deviceData->eventConfirmations), IOTHUB_CLIENT_CONFIRMATION_ERROR, deviceData->device_transport_ctx); // takes care of emptying the list too + } } + BUFFER_delete(toBeSend); } } } @@ -1827,7 +1914,7 @@ static bool abandonOrAcceptMessage(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTR { if (!( (addUserAgentHeaderInfo(handleData, abandonRequestHttpHeaders) == HTTP_HEADERS_OK) && - (HTTPHeaders_AddHeaderNameValuePair(abandonRequestHttpHeaders, "Authorization", " ") == HTTP_HEADERS_OK) && + (HTTPHeaders_AddHeaderNameValuePair(abandonRequestHttpHeaders, IOTHUB_AUTH_HEADER_VALUE, " ") == HTTP_HEADERS_OK) && (HTTPHeaders_AddHeaderNameValuePair(abandonRequestHttpHeaders, "If-Match", ETag) == HTTP_HEADERS_OK) )) { @@ -1844,7 +1931,7 @@ static bool abandonOrAcceptMessage(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTR if (deviceData->deviceSasToken != NULL) { /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/ - if (HTTPHeaders_ReplaceHeaderNameValuePair(abandonRequestHttpHeaders, "Authorization", STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK) + if (HTTPHeaders_ReplaceHeaderNameValuePair(abandonRequestHttpHeaders, IOTHUB_AUTH_HEADER_VALUE, STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK) { r = HTTPAPIEX_ERROR; /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/ @@ -2062,7 +2149,7 @@ static void DoMessages(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERD if (deviceData->deviceSasToken != NULL) { /*Codes_SRS_TRANSPORTMULTITHTTP_03_001: [if a deviceSasToken exists, HTTPHeaders_ReplaceHeaderNameValuePair shall be invoked with "Authorization" as its second argument and STRING_c_str (deviceSasToken) as its third argument.]*/ - if (HTTPHeaders_ReplaceHeaderNameValuePair(deviceData->messageHTTPrequestHeaders, "Authorization", STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK) + if (HTTPHeaders_ReplaceHeaderNameValuePair(deviceData->messageHTTPrequestHeaders, IOTHUB_AUTH_HEADER_VALUE, STRING_c_str(deviceData->deviceSasToken)) != HTTP_HEADERS_OK) { r = HTTPAPIEX_ERROR; /*Codes_SRS_TRANSPORTMULTITHTTP_03_002: [If the result of the invocation of HTTPHeaders_ReplaceHeaderNameValuePair is NOT HTTP_HEADERS_OK then fallthrough.]*/ @@ -2171,12 +2258,8 @@ static void DoMessages(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERD } else { - /*Codes_SRS_TRANSPORTMULTITHTTP_17_090: [All the HTTP headers of the form iothub-app-name:somecontent shall be transformed in message properties {name, somecontent}.]*/ - /*Codes_SRS_TRANSPORTMULTITHTTP_17_091: [The HTTP header of iothub-messageid shall be set in the MessageId.]*/ - size_t nHeaders; - if (HTTPHeaders_GetHeaderCount(responseHTTPHeaders, &nHeaders) != HTTP_HEADERS_OK) + if (retrieve_message_properties(responseHTTPHeaders, receivedMessage) != 0) { - LogError("unable to get the count of HTTP headers"); if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED)) { LogError("HTTP Transport layer failed to report ABANDON disposition"); @@ -2184,95 +2267,11 @@ static void DoMessages(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERD } else { - size_t i; - MAP_HANDLE properties = (nHeaders > 0) ? IoTHubMessage_Properties(receivedMessage) : NULL; - for (i = 0; i < nHeaders; i++) - { - char* completeHeader; - if (HTTPHeaders_GetHeader(responseHTTPHeaders, i, &completeHeader) != HTTP_HEADERS_OK) - { - break; - } - else - { - if (strncmp(IOTHUB_APP_PREFIX, completeHeader, strlen(IOTHUB_APP_PREFIX)) == 0) - { - /*looks like a property headers*/ - /*there's a guaranteed ':' in the completeHeader, by HTTP_HEADERS module*/ - char* whereIsColon = strchr(completeHeader, ':'); - if (whereIsColon != NULL) - { - *whereIsColon = '\0'; /*cut it down*/ - if (Map_AddOrUpdate(properties, completeHeader + strlen(IOTHUB_APP_PREFIX), whereIsColon + 2) != MAP_OK) /*whereIsColon+1 is a space because HTTPEHADERS outputs a ": " between name and value*/ - { - free(completeHeader); - break; - } - } - } - else if (strncmp(IOTHUB_MESSAGE_ID, completeHeader, strlen(IOTHUB_MESSAGE_ID)) == 0) - { - char* whereIsColon = strchr(completeHeader, ':'); - if (whereIsColon != NULL) - { - *whereIsColon = '\0'; /*cut it down*/ - if (IoTHubMessage_SetMessageId(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK) - { - free(completeHeader); - break; - } - } - } - else if (strncmp(IOTHUB_CORRELATION_ID, completeHeader, strlen(IOTHUB_CORRELATION_ID)) == 0) - { - char* whereIsColon = strchr(completeHeader, ':'); - if (whereIsColon != NULL) - { - *whereIsColon = '\0'; /*cut it down*/ - if (IoTHubMessage_SetCorrelationId(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK) - { - free(completeHeader); - break; - } - } - } - // Codes_SRS_TRANSPORTMULTITHTTP_09_003: [ The HTTP header value of `ContentType` shall be set in the `IoTHubMessage_SetContentTypeSystemProperty`. ] - else if (strncmp(IOTHUB_CONTENT_TYPE_C2D, completeHeader, strlen(IOTHUB_CONTENT_TYPE_C2D)) == 0) - { - char* whereIsColon = strchr(completeHeader, ':'); - if (whereIsColon != NULL) - { - *whereIsColon = '\0'; /*cut it down*/ - if (IoTHubMessage_SetContentTypeSystemProperty(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK) - { - LogError("Failed setting IoTHubMessage content-type"); - free(completeHeader); - break; - } - } - } - // Codes_SRS_TRANSPORTMULTITHTTP_09_004: [ The HTTP header value of `ContentEncoding` shall be set in the `IoTHub_SetContentEncoding`. ] - else if (strncmp(IOTHUB_CONTENT_ENCODING_C2D, completeHeader, strlen(IOTHUB_CONTENT_ENCODING_C2D)) == 0) - { - char* whereIsColon = strchr(completeHeader, ':'); - if (whereIsColon != NULL) - { - *whereIsColon = '\0'; /*cut it down*/ - if (IoTHubMessage_SetContentEncodingSystemProperty(receivedMessage, whereIsColon + 2) != IOTHUB_MESSAGE_OK) - { - LogError("Failed setting IoTHubMessage content-encoding"); - free(completeHeader); - break; - } - } - } - - free(completeHeader); - } - } - - if (i < nHeaders) + MESSAGE_CALLBACK_INFO* messageData = MESSAGE_CALLBACK_INFO_Create(receivedMessage, handleData, deviceData, etagValue); + if (messageData == NULL) { + /*Codes_SRS_TRANSPORTMULTITHTTP_10_006: [If assembling the transport context fails, _DoWork shall "abandon" the message.] */ + LogError("failed to assemble callback info"); if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED)) { LogError("HTTP Transport layer failed to report ABANDON disposition"); @@ -2280,34 +2279,21 @@ static void DoMessages(HTTPTRANSPORT_HANDLE_DATA* handleData, HTTPTRANSPORT_PERD } else { - MESSAGE_CALLBACK_INFO* messageData = MESSAGE_CALLBACK_INFO_Create(receivedMessage, handleData, deviceData, etagValue); - if (messageData == NULL) + bool abandon; + if (handleData->transport_callbacks.msg_cb(messageData, deviceData->device_transport_ctx)) { - /*Codes_SRS_TRANSPORTMULTITHTTP_10_006: [If assembling the transport context fails, _DoWork shall "abandon" the message.] */ - LogError("failed to assemble callback info"); - if (!abandonOrAcceptMessage(handleData, deviceData, etagValue, IOTHUBMESSAGE_ABANDONED)) - { - LogError("HTTP Transport layer failed to report ABANDON disposition"); - } + abandon = false; } else { - bool abandon; - if (handleData->transport_callbacks.msg_cb(messageData, deviceData->device_transport_ctx)) - { - abandon = false; - } - else - { - LogError("IoTHubClientCore_LL_MessageCallback failed"); - abandon = true; - } - - /*Codes_SRS_TRANSPORTMULTITHTTP_17_096: [If IoTHubClientCore_LL_MessageCallback returns false then _DoWork shall "abandon" the message.] */ - if (abandon) - { - (void)IoTHubTransportHttp_SendMessageDisposition(messageData, IOTHUBMESSAGE_ABANDONED); - } + LogError("IoTHubClientCore_LL_MessageCallback failed"); + abandon = true; + } + + /*Codes_SRS_TRANSPORTMULTITHTTP_17_096: [If IoTHubClientCore_LL_MessageCallback returns false then _DoWork shall "abandon" the message.] */ + if (abandon) + { + (void)IoTHubTransportHttp_SendMessageDisposition(messageData, IOTHUBMESSAGE_ABANDONED); } } } diff --git a/iothub_client/src/uamqp_messaging.c b/iothub_client/src/uamqp_messaging.c index 021fc4d461..b0bf18fc78 100644 --- a/iothub_client/src/uamqp_messaging.c +++ b/iothub_client/src/uamqp_messaging.c @@ -19,6 +19,9 @@ #include "azure_uamqp_c/message.h" #include "azure_uamqp_c/amqpvalue.h" #include "iothub_message.h" + +#include "internal/iothub_internal_consts.h" + #ifndef RESULT_OK #define RESULT_OK 0 #endif @@ -446,113 +449,197 @@ static int add_map_item(AMQP_VALUE map, const char* name, const char* value) return result; } -static int create_message_annotations_to_encode(IOTHUB_MESSAGE_HANDLE messageHandle, AMQP_VALUE *message_annotations, size_t *message_annotations_length) +static int create_diagnostic_message_annotations(IOTHUB_MESSAGE_HANDLE messageHandle, AMQP_VALUE* message_annotations_map) { - int result; - const char* distributed_tracing; + int result = RESULT_OK; + // Deprecated: maintained for backwards compatibility; use IoTHubMessage_GetDistributedTracingSystemProperty instead. const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* diagnosticData; - - result = RESULT_OK; + bool annotation_created = false; if ((diagnosticData = IoTHubMessage_GetDiagnosticPropertyData(messageHandle)) != NULL && diagnosticData->diagnosticId != NULL && diagnosticData->diagnosticCreationTimeUtc != NULL) { - AMQP_VALUE message_annotations_map = NULL; - // Codes_SRS_UAMQP_MESSAGING_32_001: [If optional diagnostic properties are present in the iot hub message, encode them into the AMQP message as annotation properties. Errors stop processing on this message.] - if ((message_annotations_map = amqpvalue_create_map()) == NULL) + if (*message_annotations_map == NULL) { - LogError("Failed amqpvalue_create_map for annotations"); - result = __FAILURE__; + if ((*message_annotations_map = amqpvalue_create_map()) == NULL) + { + LogError("Failed amqpvalue_create_map for annotations"); + result = __FAILURE__; + } + else + { + annotation_created = true; + } } - else + + if (result == RESULT_OK) { char* diagContextBuffer = NULL; - - if (add_map_item(message_annotations_map, AMQP_DIAGNOSTIC_ID_KEY, diagnosticData->diagnosticId) != RESULT_OK) + if (add_map_item(*message_annotations_map, AMQP_DIAGNOSTIC_ID_KEY, diagnosticData->diagnosticId) != RESULT_OK) { LogError("Failed adding diagnostic id"); result = __FAILURE__; + if (annotation_created) + { + amqpvalue_destroy(*message_annotations_map); + *message_annotations_map = NULL; + } } else if ((diagContextBuffer = (char*)malloc(strlen(AMQP_DIAGNOSTIC_CREATION_TIME_UTC_KEY) + 1 + strlen(diagnosticData->diagnosticCreationTimeUtc) + 1)) == NULL) { LogError("Failed malloc for diagnostic context"); result = __FAILURE__; + if (annotation_created) + { + amqpvalue_destroy(*message_annotations_map); + *message_annotations_map = NULL; + } } else if (sprintf(diagContextBuffer, "%s=%s", AMQP_DIAGNOSTIC_CREATION_TIME_UTC_KEY, diagnosticData->diagnosticCreationTimeUtc) < 0) { LogError("Failed sprintf diagnostic context"); result = __FAILURE__; + if (annotation_created) + { + amqpvalue_destroy(*message_annotations_map); + *message_annotations_map = NULL; + } } - else if (add_map_item(message_annotations_map, AMQP_DIAGNOSTIC_CONTEXT_KEY, diagContextBuffer) != RESULT_OK) + else if (add_map_item(*message_annotations_map, AMQP_DIAGNOSTIC_CONTEXT_KEY, diagContextBuffer) != RESULT_OK) { LogError("Failed adding diagnostic context"); result = __FAILURE__; + if (annotation_created) + { + amqpvalue_destroy(*message_annotations_map); + *message_annotations_map = NULL; + } } - else if((*message_annotations = amqpvalue_create_message_annotations(message_annotations_map)) == NULL) - { - LogError("Failed creating message annotations"); - result = __FAILURE__; - } - else if (amqpvalue_get_encoded_size(*message_annotations, message_annotations_length) != 0) + free(diagContextBuffer); + } + } + return result; +} + +static int create_distributed_tracing_message_annotations(IOTHUB_MESSAGE_HANDLE messageHandle, AMQP_VALUE* message_annotations_map) +{ + int result = RESULT_OK; + const char* distributed_tracing = IoTHubMessage_GetDistributedTracingSystemProperty(messageHandle); + bool annotation_created = false; + + if (distributed_tracing != NULL) + { + if (*message_annotations_map == NULL) + { + // Codes_SRS_UAMQP_MESSAGING_32_001: [If optional diagnostic properties are present in the iot hub message, encode them into the AMQP message as annotation properties. Errors stop processing on this message.] + + if ((*message_annotations_map = amqpvalue_create_map()) == NULL) { - LogError("Failed getting size of annotations"); + LogError("Failed amqpvalue_create_map for annotations"); result = __FAILURE__; } else { - result = RESULT_OK; + annotation_created = true; } - - free(diagContextBuffer); - amqpvalue_destroy(message_annotations_map); - } - } - - // Distributed tracing - if (result == RESULT_OK && (distributed_tracing = IoTHubMessage_GetDistributedTracingSystemProperty(messageHandle)) != NULL) - { - AMQP_VALUE message_annotations_map = NULL; - - // Codes_SRS_UAMQP_MESSAGING_32_001: [If optional diagnostic properties are present in the iot hub message, encode them into the AMQP message as annotation properties. Errors stop processing on this message.] - if ((message_annotations_map = amqpvalue_create_map()) == NULL) - { - LogError("Failed amqpvalue_create_map for annotations"); - result = __FAILURE__; } - else + + if (result == RESULT_OK) { - if (add_map_item(message_annotations_map, AMQP_DISTRIBUTED_TRACING_KEY, distributed_tracing) != RESULT_OK) + if (add_map_item(*message_annotations_map, AMQP_DISTRIBUTED_TRACING_KEY, distributed_tracing) != RESULT_OK) { LogError("Failed adding distributed tracing property"); result = __FAILURE__; + if (annotation_created) + { + amqpvalue_destroy(*message_annotations_map); + *message_annotations_map = NULL; + } } - else if ((*message_annotations = amqpvalue_create_message_annotations(message_annotations_map)) == NULL) - { - LogError("Failed creating message annotations"); - result = __FAILURE__; - } - else if (amqpvalue_get_encoded_size(*message_annotations, message_annotations_length) != 0) + } + } + + return result; +} + +static int create_security_message_annotations(IOTHUB_MESSAGE_HANDLE messageHandle, AMQP_VALUE* message_annotations_map) +{ + int result = RESULT_OK; + bool annotation_created = false; + if (IoTHubMessage_IsSecurityMessage(messageHandle)) + { + if (*message_annotations_map == NULL) + { + if ((*message_annotations_map = amqpvalue_create_map()) == NULL) { - LogError("Failed getting size of annotations"); + LogError("Failed amqpvalue_create_map for annotations"); result = __FAILURE__; } else { - result = RESULT_OK; + annotation_created = true; } + } - amqpvalue_destroy(message_annotations_map); + if (result == RESULT_OK) + { + if (add_map_item(*message_annotations_map, SECURITY_INTERFACE_ID, SECURITY_INTERFACE_ID_VALUE) != RESULT_OK) + { + LogError("Failed adding Security interface id"); + result = __FAILURE__; + if (annotation_created) + { + amqpvalue_destroy(*message_annotations_map); + *message_annotations_map = NULL; + } + } } } + return result; +} + +static int create_message_annotations_to_encode(IOTHUB_MESSAGE_HANDLE messageHandle, AMQP_VALUE *message_annotations, size_t *message_annotations_length) +{ + AMQP_VALUE message_annotations_map = NULL; + int result; + + if ((result = create_diagnostic_message_annotations(messageHandle, &message_annotations_map)) != RESULT_OK) + { + LogError("Failed creating message annotations"); + result = __FAILURE__; + } + else if ((result = create_distributed_tracing_message_annotations(messageHandle, &message_annotations_map)) != RESULT_OK) + { + LogError("Failed creating distributed message annotations"); + result = __FAILURE__; + } + else if ((result = create_security_message_annotations(messageHandle, &message_annotations_map)) != RESULT_OK) + { + LogError("Failed creating message annotations"); + result = __FAILURE__; + } else { - // Codes_SRS_UAMQP_MESSAGING_32_002: [If optional diagnostic properties are not present in the iot hub message, no error should happen.] result = RESULT_OK; } + if (result == RESULT_OK && message_annotations_map != NULL) + { + if ((*message_annotations = amqpvalue_create_message_annotations(message_annotations_map)) == NULL) + { + LogError("Failed creating message annotations"); + result = __FAILURE__; + } + else if (amqpvalue_get_encoded_size(*message_annotations, message_annotations_length) != 0) + { + LogError("Failed getting size of annotations"); + result = __FAILURE__; + } + amqpvalue_destroy(message_annotations_map); + } return result; } diff --git a/iothub_client/tests/CMakeLists.txt b/iothub_client/tests/CMakeLists.txt index 991bf84ea7..e1dc8f9efc 100644 --- a/iothub_client/tests/CMakeLists.txt +++ b/iothub_client/tests/CMakeLists.txt @@ -79,9 +79,9 @@ if(${use_mqtt}) add_sfctest_directory(iothubclient_mqtt_dm_e2e_sfc) add_e2etest_directory(iothubclient_mqtt_mod_dm_e2e) add_e2etest_directory(iothubclient_mqtt_mod_dt_e2e) - #add_e2etest_directory(iothubclient_mqtt_ds_e2e) - #add_e2etest_directory(iothubclient_mqtt_ws_ds_e2e) - #add_e2etest_directory(iothubclient_mqtt_mod_ds_e2e) + add_e2etest_directory(iothubclient_mqtt_ds_e2e) + add_e2etest_directory(iothubclient_mqtt_ws_ds_e2e) + add_e2etest_directory(iothubclient_mqtt_mod_ds_e2e) if(NOT ${use_wolfssl}) add_e2etest_directory(iothubclient_mqtt_ws_e2e) add_sfctest_directory(iothubclient_mqtt_ws_e2e_sfc) @@ -117,9 +117,9 @@ if(${use_amqp}) add_e2etest_directory(iothubclient_amqp_mod_dm_e2e) add_e2etest_directory(iothubclient_amqp_mod_dt_e2e) - # add_e2etest_directory(iothubclient_amqp_ds_e2e) - # add_e2etest_directory(iothubclient_amqp_ws_ds_e2e) - #add_e2etest_directory(iothubclient_amqp_mod_ds_e2e) + add_e2etest_directory(iothubclient_amqp_ds_e2e) + add_e2etest_directory(iothubclient_amqp_ws_ds_e2e) + add_e2etest_directory(iothubclient_amqp_mod_ds_e2e) if(NOT ${use_wolfssl}) add_e2etest_directory(iothubclient_amqp_ws_e2e) add_sfctest_directory(iothubclient_amqp_ws_e2e_sfc) diff --git a/iothub_client/tests/blob_ut/blob_ut.c b/iothub_client/tests/blob_ut/blob_ut.c index 4d2cfd6c17..12f5a8c5cb 100644 --- a/iothub_client/tests/blob_ut/blob_ut.c +++ b/iothub_client/tests/blob_ut/blob_ut.c @@ -26,7 +26,7 @@ static void my_gballoc_free(void* s) #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/httpheaders.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/shared_util_options.h" @@ -102,7 +102,7 @@ static void my_STRING_delete(STRING_HANDLE h) my_gballoc_free((void*)h); } -static STRING_HANDLE my_Base64_Encode_Bytes(const unsigned char* source, size_t size) +static STRING_HANDLE my_Azure_Base64_Encode_Bytes(const unsigned char* source, size_t size) { (void)source; (void)size; @@ -260,8 +260,8 @@ TEST_SUITE_INITIALIZE(TestSuiteInitialize) REGISTER_GLOBAL_MOCK_HOOK(STRING_construct, my_STRING_construct); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_construct, NULL); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encode_Bytes, my_Base64_Encode_Bytes); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode_Bytes, my_Azure_Base64_Encode_Bytes); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_concat, __FAILURE__); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_concat_with_STRING, __FAILURE__); @@ -364,7 +364,7 @@ TEST_FUNCTION(Blob_UploadMultipleBlocksFromSasUri_succeeds_when_HTTP_status_code )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ .IgnoreArgument_source(); STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ @@ -441,7 +441,7 @@ TEST_FUNCTION(Blob_UploadMultipleBlocksFromSasUri_fails_when_HTTPAPIEX_ExecuteRe )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ .IgnoreArgument_source(); STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ @@ -677,7 +677,7 @@ static void Blob_UploadMultipleBlocksFromSasUri_various_sizes_happy_path_Impl(HT )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ .IgnoreArgument_source(); STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ @@ -859,7 +859,7 @@ TEST_FUNCTION(Blob_UploadMultipleBlocksFromSasUri_various_sizes_with_certificate )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ .IgnoreArgument_source(); STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ @@ -1062,7 +1062,7 @@ TEST_FUNCTION(Blob_UploadMultipleBlocksFromSasUri_64MB_unhappy_paths) )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ /*3, 16, 29... (16 numbers)*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ /*3, 16, 29... (16 numbers)*/ .IgnoreArgument_source(); STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ @@ -1161,7 +1161,7 @@ TEST_FUNCTION(Blob_UploadMultipleBlocksFromSasUri_64MB_unhappy_paths) umock_c_negative_tests_fail_call(i); char temp_str[128]; sprintf(temp_str, "On failed call %lu", (unsigned long)i); - + ///act context.toUpload = context.size; /* Reinit context */ BLOB_RESULT result = Blob_UploadMultipleBlocksFromSasUri("https://h.h/something?a=b", FileUpload_GetData_Callback, &context, &httpResponse, testValidBufferHandle, NULL, NULL); @@ -1292,7 +1292,7 @@ TEST_FUNCTION(Blob_UploadMultipleBlocksFromSasUri_64MB_with_certificate_unhappy_ )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ /*3, 16, 29... (16 numbers)*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ /*3, 16, 29... (16 numbers)*/ .IgnoreArgument_source(); /* 5 */ STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ @@ -1440,7 +1440,7 @@ TEST_FUNCTION(Blob_UploadFromSasUri_when_http_code_is_404_it_immediately_succeed )); /*this is the content to be uploaded by this call*/ /*here some sprintf happens and that produces a string in the form: 000000...049999*/ - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, 6)) /*this is converting the produced blockID string to a base64 representation*/ .IgnoreArgument_source(); STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, "")) /*this is building the XML*/ diff --git a/iothub_client/tests/common_ds_e2e/iothubclient_common_ds_e2e.c b/iothub_client/tests/common_ds_e2e/iothubclient_common_ds_e2e.c index e52387a687..229e76cea8 100644 --- a/iothub_client/tests/common_ds_e2e/iothubclient_common_ds_e2e.c +++ b/iothub_client/tests/common_ds_e2e/iothubclient_common_ds_e2e.c @@ -24,7 +24,6 @@ #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" #include "azure_c_shared_utility/threadapi.h" #include "azure_c_shared_utility/uniqueid.h" @@ -89,7 +88,7 @@ typedef struct EXPECTED_DEVICE_STREAMING_REQUEST_TAG { char* streamName; bool shouldAccept; - size_t responseDelaySecs; + unsigned int responseDelaySecs; DEVICE_STREAM_C2D_REQUEST* request; TEST_DEVICE_STREAMING_RESPONSE* response; } EXPECTED_DEVICE_STREAMING_REQUEST; @@ -98,8 +97,11 @@ typedef struct WEBSOCKET_CLIENT_CONTEXT_TAG { bool isDeviceClient; bool isOpen; + bool hadOpenError; + bool hadSendError; bool isFaulty; - bool isCloseAckd; + bool remoteCloseReceived; + bool localCloseConfirmed; char* dataSent; char* dataReceived; EXPECTED_DEVICE_STREAMING_REQUEST* expDSReq; @@ -311,9 +313,9 @@ static int parse_device_streaming_response(HTTP_HEADERS_HANDLE httpResponseHeade bool* isAccepted, char** url, char** authorizationToken) { int result; - char* isAcceptedCharPtr; + const char* isAcceptedCharPtr; - if ((isAcceptedCharPtr = findAndCloneHttpHeaderValue(httpResponseHeaders, DEVICE_STREAMING_RESPONSE_FIELD_IS_ACCEPTED)) == NULL) + if ((isAcceptedCharPtr = HTTPHeaders_FindHeaderValue(httpResponseHeaders, DEVICE_STREAMING_RESPONSE_FIELD_IS_ACCEPTED)) == NULL) { LogError("Failed parsing device streaming response (%s)", DEVICE_STREAMING_RESPONSE_FIELD_IS_ACCEPTED); result = __FAILURE__; @@ -466,6 +468,8 @@ static int ds_e2e_send_device_streaming_request_async(const char* deviceId, cons result = __FAILURE__; } } + + BUFFER_delete(responseBuffer); } HTTPHeaders_Free(httpResponseHeaders); @@ -508,26 +512,26 @@ static void setoption_on_device_or_module(const char * optionName, const void * static void connection_status_callback(IOTHUB_CLIENT_CONNECTION_STATUS status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* userContextCallback) { (void)userContextCallback; - LogInfo("connection_status_callback: status=<%d>, reason=<%s>", status, ENUM_TO_STRING(IOTHUB_CLIENT_CONNECTION_STATUS_REASON, reason)); + LogInfo("[TEST] connection_status_callback: status=<%d>, reason=<%s>", status, ENUM_TO_STRING(IOTHUB_CLIENT_CONNECTION_STATUS_REASON, reason)); } -static void setconnectionstatuscallback_on_device_or_module() +static void setconnectionstatuscallback_on_device_or_module(DEVICE_STREAMING_TEST_CONTEXT* client_state) { IOTHUB_CLIENT_RESULT result; if (iothub_moduleclient_handle != NULL) { - result = IoTHubModuleClient_SetConnectionStatusCallback(iothub_moduleclient_handle, connection_status_callback, NULL); + result = IoTHubModuleClient_SetConnectionStatusCallback(iothub_moduleclient_handle, connection_status_callback, client_state); } else { - result = IoTHubDeviceClient_SetConnectionStatusCallback(iothub_deviceclient_handle, connection_status_callback, NULL); + result = IoTHubDeviceClient_SetConnectionStatusCallback(iothub_deviceclient_handle, connection_status_callback, client_state); } ASSERT_ARE_EQUAL(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_OK, result, "Could not set connection Status Callback"); } -static void client_connect_to_hub(IOTHUB_PROVISIONED_DEVICE* deviceToUse, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol) +static void client_connect_to_hub(IOTHUB_PROVISIONED_DEVICE* deviceToUse, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol, DEVICE_STREAMING_TEST_CONTEXT* device_client_state) { ASSERT_IS_NULL(iothub_deviceclient_handle, "iothub_deviceclient_handle is non-NULL on test initialization"); ASSERT_IS_NULL(iothub_moduleclient_handle, "iothub_moduleclient_handle is non-NULL on test initialization"); @@ -548,7 +552,7 @@ static void client_connect_to_hub(IOTHUB_PROVISIONED_DEVICE* deviceToUse, IOTHUB #endif // SET_TRUSTED_CERT_IN_SAMPLES // Set connection status change callback - setconnectionstatuscallback_on_device_or_module(); + setconnectionstatuscallback_on_device_or_module(device_client_state); if (deviceToUse->howToCreate == IOTHUB_ACCOUNT_AUTH_X509) { @@ -605,7 +609,7 @@ static char* get_me_a_new_stream_name() } static EXPECTED_DEVICE_STREAMING_REQUEST* add_expected_streaming_request( - DEVICE_STREAMING_TEST_CONTEXT* dsTestCtx, bool shouldAccept, size_t responseDelaySecs) + DEVICE_STREAMING_TEST_CONTEXT* dsTestCtx, bool shouldAccept, unsigned int responseDelaySecs) { EXPECTED_DEVICE_STREAMING_REQUEST* result; LIST_ITEM_HANDLE list_item; @@ -681,6 +685,8 @@ static void destroy_device_streaming_test_context(DEVICE_STREAMING_TEST_CONTEXT* { (void)singlylinkedlist_remove_if(dsTestCtx->expectedRequests, destroy_expected_streaming_request_in_list, NULL); (void)singlylinkedlist_remove_if(dsTestCtx->requestsReceived, destroy_device_streaming_requests_in_list, NULL); + singlylinkedlist_destroy(dsTestCtx->expectedRequests); + singlylinkedlist_destroy(dsTestCtx->requestsReceived); free(dsTestCtx); } @@ -749,8 +755,6 @@ static void set_device_streaming_callback(DEVICE_STREAMING_TEST_CONTEXT* dsTestC } ASSERT_ARE_EQUAL(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_OK, result, "SetStreamRequestCallback failed"); - - ThreadAPI_Sleep(2000); // Waiting a little bit until subscription is good. } static int verify_device_streaming_requests_received(DEVICE_STREAMING_TEST_CONTEXT* dsTestCtx) @@ -759,7 +763,7 @@ static int verify_device_streaming_requests_received(DEVICE_STREAMING_TEST_CONTE if (dsTestCtx->numOfRequestsReceived != dsTestCtx->numOfRequestsExpected) { - LogError("Expected %d stream requests, but got %d", (int)dsTestCtx->numOfRequestsExpected, (int)dsTestCtx->numOfRequestsReceived); + LogError("[TEST] Expected %d stream requests, but got %d", (int)dsTestCtx->numOfRequestsExpected, (int)dsTestCtx->numOfRequestsReceived); result = __FAILURE__; } else @@ -774,12 +778,12 @@ static int verify_device_streaming_requests_received(DEVICE_STREAMING_TEST_CONTE if (expDSReq->request == NULL) { - LogError("Did not received request for stream %s", expDSReq->streamName); + LogError("[TEST] Did not received request for stream %s", expDSReq->streamName); result = __FAILURE__; } else if (expDSReq->response->isAccepted != expDSReq->shouldAccept) { - LogError("Unexpected response for stream request (%s, shouldAccept=%d, isAccepted=%d", expDSReq->streamName, (int)expDSReq->shouldAccept, (int)expDSReq->response->isAccepted); + LogError("[TEST] Unexpected response for stream request (%s, shouldAccept=%d, isAccepted=%d", expDSReq->streamName, (int)expDSReq->shouldAccept, (int)expDSReq->response->isAccepted); result = __FAILURE__; } @@ -803,19 +807,18 @@ static void on_ws_open_complete(void* context, WS_OPEN_RESULT ws_open_result) } else { - clientCtx->isFaulty = true; - LogError("[TEST] on_ws_open_complete (%s, %d, %s)", clientCtx->expDSReq->streamName, (int)clientCtx->isDeviceClient, ENUM_TO_STRING(WS_OPEN_RESULT, ws_open_result)); + clientCtx->hadOpenError = true; } } static void on_ws_send_frame_complete(void* context, WS_SEND_FRAME_RESULT ws_send_frame_result) { - if (ws_send_frame_result != WS_SEND_FRAME_OK) + if (ws_send_frame_result != WS_SEND_FRAME_OK && ws_send_frame_result != WS_SEND_FRAME_CANCELLED) { WEBSOCKET_CLIENT_CONTEXT* clientCtx = (WEBSOCKET_CLIENT_CONTEXT*)context; LogError("[TEST] Failed sending stream data (%s, %d, %s)", clientCtx->expDSReq->streamName, (int)clientCtx->isDeviceClient, ENUM_TO_STRING(WS_SEND_FRAME_RESULT, ws_send_frame_result)); - clientCtx->isFaulty = true; + clientCtx->hadSendError = true; } } @@ -842,27 +845,33 @@ static void on_ws_frame_received(void* context, unsigned char frame_type, const WEBSOCKET_CLIENT_CONTEXT* clientCtx = (WEBSOCKET_CLIENT_CONTEXT*)context; + if (clientCtx->dataReceived != NULL) + { + free(clientCtx->dataReceived); + } + clientCtx->dataReceived = cloneToNullTerminatedString(buffer, size); + ASSERT_IS_NOT_NULL(clientCtx->dataReceived, "Failed copying received data frame (%s; %d)", clientCtx->expDSReq->streamName, clientCtx->isDeviceClient); } static void on_ws_peer_closed(void* context, uint16_t* close_code, const unsigned char* extra_data, size_t extra_data_length) { WEBSOCKET_CLIENT_CONTEXT* clientCtx = (WEBSOCKET_CLIENT_CONTEXT*)context; - LogInfo("on_ws_peer_closed (%s; %d; Code=%d; Data=%.*s)", clientCtx->expDSReq->streamName, (int)clientCtx->isDeviceClient, *(int*)close_code, (int)extra_data_length, (const char*)extra_data); + LogInfo("[TEST] on_ws_peer_closed (%s; %d; Code=%d; Data=%.*s)", clientCtx->expDSReq->streamName, (int)clientCtx->isDeviceClient, *(int*)close_code, (int)extra_data_length, (const char*)extra_data); + clientCtx->remoteCloseReceived = true; } static void on_ws_closed(void* context) { WEBSOCKET_CLIENT_CONTEXT* clientCtx = (WEBSOCKET_CLIENT_CONTEXT*)context; - clientCtx->isCloseAckd = true; + clientCtx->localCloseConfirmed = true; } - static void on_ws_error(void* context, WS_ERROR error_code) { WEBSOCKET_CLIENT_CONTEXT* clientCtx = (WEBSOCKET_CLIENT_CONTEXT*)context; - LogError("on_ws_error (%s, %d, %s)\r\n", clientCtx->expDSReq->streamName, (int)clientCtx->isDeviceClient, ENUM_TO_STRING(WS_ERROR, error_code)); + LogError("[TEST] on_ws_error (%s, %d, %s)\r\n", clientCtx->expDSReq->streamName, (int)clientCtx->isDeviceClient, ENUM_TO_STRING(WS_ERROR, error_code)); clientCtx->isFaulty = true; } @@ -873,7 +882,7 @@ static int parse_streaming_gateway_url(char* url, char** hostAddress, size_t* po if ((ws_url = ws_url_create(url)) == NULL) { - LogError("Failed creating WS url parser"); + LogError("[TEST] Failed creating WS url parser"); result = __FAILURE__; } else @@ -883,7 +892,7 @@ static int parse_streaming_gateway_url(char* url, char** hostAddress, size_t* po if (ws_url_get_host(ws_url, &host_value, &host_length) != 0) { - LogError("Failed getting the host part of the WS url"); + LogError("[TEST] Failed getting the host part of the WS url"); result = __FAILURE__; } else @@ -893,26 +902,26 @@ static int parse_streaming_gateway_url(char* url, char** hostAddress, size_t* po if (ws_url_get_path(ws_url, &path_value, &path_length) != 0) { - LogError("Failed getting the path part of the WS url"); + LogError("[TEST] Failed getting the path part of the WS url"); result = __FAILURE__; } else { if ((*hostAddress = cloneToNullTerminatedString((const unsigned char*)host_value, host_length)) == NULL) { - LogError("Failed setting host address"); + LogError("[TEST] Failed setting host address"); result = __FAILURE__; } else if ((*resourceName = cloneToNullTerminatedString((const unsigned char*)(path_value - 1), path_length + 1)) == NULL) { - LogError("Failed setting resource name"); + LogError("[TEST] Failed setting resource name"); free(*hostAddress); *hostAddress = NULL; result = __FAILURE__; } else if (ws_url_get_port(ws_url, port) != 0) { - LogError("Failed getting the port part of the WS url"); + LogError("[TEST] Failed getting the port part of the WS url"); free(*hostAddress); *hostAddress = NULL; free(*resourceName); @@ -956,7 +965,7 @@ static UWS_CLIENT_HANDLE create_websocket_client(char* url, char* authorizationT LogError("[TEST] Failed setting authorization header"); result = NULL; } - else if ((result = uws_client_create(hostAddress, port, resourceName, true, &protocols, 1)) == NULL) + else if ((result = uws_client_create(hostAddress, (unsigned int)port, resourceName, true, &protocols, 1)) == NULL) { LogError("[TEST] Failed creating uws_client"); result = NULL; @@ -989,8 +998,11 @@ static int verify_single_streaming_through_gateway(EXPECTED_DEVICE_STREAMING_REQ deviceClientCtx.isDeviceClient = true; deviceClientCtx.isOpen = false; - deviceClientCtx.isCloseAckd = false; + deviceClientCtx.hadOpenError = false; + deviceClientCtx.hadSendError = false; deviceClientCtx.isFaulty = false; + deviceClientCtx.remoteCloseReceived = false; + deviceClientCtx.localCloseConfirmed = false; deviceClientCtx.dataSent = NULL; deviceClientCtx.dataReceived = NULL; deviceClientCtx.expDSReq = expDSReq; @@ -1007,8 +1019,11 @@ static int verify_single_streaming_through_gateway(EXPECTED_DEVICE_STREAMING_REQ serviceClientCtx.isDeviceClient = false; serviceClientCtx.isOpen = false; - serviceClientCtx.isCloseAckd = false; + serviceClientCtx.hadOpenError = false; + serviceClientCtx.hadSendError = false; serviceClientCtx.isFaulty = false; + serviceClientCtx.remoteCloseReceived = false; + serviceClientCtx.localCloseConfirmed = false; serviceClientCtx.dataSent = NULL; serviceClientCtx.dataReceived = NULL; serviceClientCtx.expDSReq = expDSReq; @@ -1024,9 +1039,10 @@ static int verify_single_streaming_through_gateway(EXPECTED_DEVICE_STREAMING_REQ { result = 0; - while (!serviceClientCtx.isCloseAckd && !deviceClientCtx.isCloseAckd) + while (!serviceClientCtx.localCloseConfirmed && !serviceClientCtx.remoteCloseReceived && + !deviceClientCtx.localCloseConfirmed && !deviceClientCtx.remoteCloseReceived) { - if (serviceClientCtx.isFaulty) + if (serviceClientCtx.hadOpenError || serviceClientCtx.isFaulty || serviceClientCtx.hadSendError) { LogError("[TEST] WS client is faulty (service client; %s)", expDSReq->streamName); result = __FAILURE__; @@ -1068,7 +1084,7 @@ static int verify_single_streaming_through_gateway(EXPECTED_DEVICE_STREAMING_REQ } } - if (deviceClientCtx.isFaulty) + if (deviceClientCtx.hadOpenError || deviceClientCtx.isFaulty || deviceClientCtx.hadSendError) { LogError("[TEST] WS client is faulty (device client; %s)", expDSReq->streamName); result = __FAILURE__; @@ -1103,14 +1119,20 @@ static int verify_single_streaming_through_gateway(EXPECTED_DEVICE_STREAMING_REQ { if (strcmp(serviceClientCtx.dataSent, serviceClientCtx.dataReceived) != 0) { - LogError("Data sent and received by service WS client do not match ('%s'; '%s')", + LogError("[TEST] Data sent and received by service WS client do not match ('%s'; '%s')", serviceClientCtx.dataSent, serviceClientCtx.dataReceived); result = __FAILURE__; } } - free(deviceClientCtx.dataReceived); - free(serviceClientCtx.dataReceived); + if (deviceClientCtx.dataReceived != NULL) + { + free(deviceClientCtx.dataReceived); + } + if (serviceClientCtx.dataReceived != NULL) + { + free(serviceClientCtx.dataReceived); + } } return result; @@ -1130,7 +1152,7 @@ static int verify_streaming_through_gateway(DEVICE_STREAMING_TEST_CONTEXT* dsTes if (list_item == NULL) { - LogError("[TEST FAILURE] Failed getting expected request from list"); + LogError("[TEST] Failed getting expected request from list"); result = __FAILURE__; } else @@ -1163,25 +1185,41 @@ static int verify_streaming_through_gateway(DEVICE_STREAMING_TEST_CONTEXT* dsTes return result; } + // ========== Public API ========== // +#define MAX_SEND_REQUEST_COUNT 10 + static void receive_device_streaming_request_test(IOTHUB_PROVISIONED_DEVICE* deviceToUse, IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol, bool shouldAcceptRequest) { // arrange - int send_request_result; int verify_request_result; int streaming_result; + int send_request_counter = 0; DEVICE_STREAMING_TEST_CONTEXT* dsTestCtx = create_device_streaming_test_context(); // Create the IoT Hub Data - client_connect_to_hub(deviceToUse, protocol); + client_connect_to_hub(deviceToUse, protocol, dsTestCtx); set_device_streaming_callback(dsTestCtx); EXPECTED_DEVICE_STREAMING_REQUEST* request = add_expected_streaming_request(dsTestCtx, shouldAcceptRequest, 0); - send_request_result = ds_e2e_send_device_streaming_request_async(deviceToUse->deviceId, deviceToUse->moduleId, request); - ASSERT_ARE_EQUAL(int, 0, send_request_result, "Something failed sending device streaming request"); + while (true) + { + if (ds_e2e_send_device_streaming_request_async(deviceToUse->deviceId, deviceToUse->moduleId, request) == 0) + { + break; + } + else if (send_request_counter++ < MAX_SEND_REQUEST_COUNT) + { + ThreadAPI_Sleep(500); + } + else + { + ASSERT_FAIL("Timed-out sending device streaming request"); + } + } verify_request_result = verify_device_streaming_requests_received(dsTestCtx); ASSERT_ARE_EQUAL(int, 0, verify_request_result); diff --git a/iothub_client/tests/iothub_client_authorization_ut/iothub_client_authorization_ut.c b/iothub_client/tests/iothub_client_authorization_ut/iothub_client_authorization_ut.c index 74f9758d56..c1a007ec97 100644 --- a/iothub_client/tests/iothub_client_authorization_ut/iothub_client_authorization_ut.c +++ b/iothub_client/tests/iothub_client_authorization_ut/iothub_client_authorization_ut.c @@ -198,12 +198,12 @@ TEST_FUNCTION_CLEANUP(method_cleanup) static void setup_IoTHubClient_Auth_CreateFromDeviceAuth_mocks(bool module_id, DEVICE_AUTH_TYPE auth_type) { STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); - STRICT_EXPECTED_CALL(iothub_device_auth_create()); STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, DEVICE_ID)); if (module_id) { STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, MODULE_ID)); } + STRICT_EXPECTED_CALL(iothub_device_auth_create()); STRICT_EXPECTED_CALL(iothub_device_auth_get_type(IGNORED_PTR_ARG)).SetReturn(auth_type); } #endif @@ -211,15 +211,15 @@ static void setup_IoTHubClient_Auth_CreateFromDeviceAuth_mocks(bool module_id, D static void setup_IoTHubClient_Auth_Create_mocks(bool device_key, bool module_id) { STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); - if (device_key) - { - STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, DEVICE_KEY)); - } STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, DEVICE_ID)); if (module_id) { STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, MODULE_ID)); } + if (device_key) + { + STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, DEVICE_KEY)); + } } static void setup_IoTHubClient_Auth_Get_ConnString_mocks() @@ -392,8 +392,11 @@ TEST_FUNCTION(IoTHubClient_Auth_Create_fail) IOTHUB_AUTHORIZATION_HANDLE handle = IoTHubClient_Auth_Create(DEVICE_KEY, DEVICE_ID, NULL, MODULE_ID); + char tmp_msg[64]; + sprintf(tmp_msg, "IoTHubClient_Auth_Create failure in test %lu/%lu", (unsigned long)index, (unsigned long)count); + //assert - ASSERT_IS_NULL(handle, "IoTHubClient_Auth_Create failure in test %lu/%lu", (unsigned long)index, (unsigned long)count); + ASSERT_IS_NULL(handle, tmp_msg); } //cleanup umock_c_negative_tests_deinit(); @@ -405,10 +408,10 @@ TEST_FUNCTION(IoTHubClient_Auth_CreateFromDeviceAuth_success) //arrange umock_c_reset_all_calls(); - setup_IoTHubClient_Auth_CreateFromDeviceAuth_mocks(false, AUTH_TYPE_SAS); + setup_IoTHubClient_Auth_CreateFromDeviceAuth_mocks(true, AUTH_TYPE_SAS); //act - IOTHUB_AUTHORIZATION_HANDLE handle = IoTHubClient_Auth_CreateFromDeviceAuth(DEVICE_ID, NULL); + IOTHUB_AUTHORIZATION_HANDLE handle = IoTHubClient_Auth_CreateFromDeviceAuth(DEVICE_ID, MODULE_ID); //assert ASSERT_IS_NOT_NULL(handle); @@ -452,13 +455,13 @@ TEST_FUNCTION(IoTHubClient_Auth_CreateFromDeviceAuth_fail) umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(index); + IOTHUB_AUTHORIZATION_HANDLE handle = IoTHubClient_Auth_CreateFromDeviceAuth(DEVICE_ID, MODULE_ID); + char tmp_msg[64]; sprintf(tmp_msg, "IoTHubClient_Auth_Create failure in test %lu/%lu", (unsigned long)index, (unsigned long)count); - IOTHUB_AUTHORIZATION_HANDLE handle = IoTHubClient_Auth_CreateFromDeviceAuth(DEVICE_ID, MODULE_ID); - //assert - ASSERT_IS_NULL(handle); + ASSERT_IS_NULL(handle, tmp_msg); } //cleanup @@ -827,6 +830,7 @@ TEST_FUNCTION(IoTHubClient_Auth_Get_ModuleId_succeed) setup_IoTHubClient_Auth_Create_mocks(false, true); IOTHUB_AUTHORIZATION_HANDLE handle = IoTHubClient_Auth_Create(NULL, DEVICE_ID, NULL, MODULE_ID); ASSERT_IS_NOT_NULL(handle); + umock_c_reset_all_calls(); //act const char* module_id = IoTHubClient_Auth_Get_ModuleId(handle); diff --git a/iothub_client/tests/iothubclient_amqp_ws_ds_e2e/CMakeLists.txt b/iothub_client/tests/iothubclient_amqp_ws_ds_e2e/CMakeLists.txt index 403d2c2f81..53ffbe283c 100644 --- a/iothub_client/tests/iothubclient_amqp_ws_ds_e2e/CMakeLists.txt +++ b/iothub_client/tests/iothubclient_amqp_ws_ds_e2e/CMakeLists.txt @@ -46,7 +46,7 @@ if(WIN32) target_link_libraries(${theseTestsName}_dll iothub_test iothub_client - iothub_client_amqp_transport + iothub_client_amqp_ws_transport iothub_service_client aziotsharedutil rpcrt4 @@ -59,7 +59,7 @@ if(WIN32) target_link_libraries(${theseTestsName}_exe iothub_test iothub_client - iothub_client_amqp_transport + iothub_client_amqp_ws_transport iothub_service_client aziotsharedutil rpcrt4 @@ -92,7 +92,7 @@ else() target_link_libraries(${theseTestsName}_exe iothub_test iothub_client - iothub_client_amqp_transport + iothub_client_amqp_ws_transport iothub_service_client aziotsharedutil ) diff --git a/iothub_client/tests/iothubclient_ll_u2b_ut/iothub_client_ll_u2b_ut.c b/iothub_client/tests/iothubclient_ll_u2b_ut/iothub_client_ll_u2b_ut.c index 6854c2a829..451631f8a9 100644 --- a/iothub_client/tests/iothubclient_ll_u2b_ut/iothub_client_ll_u2b_ut.c +++ b/iothub_client/tests/iothubclient_ll_u2b_ut/iothub_client_ll_u2b_ut.c @@ -69,7 +69,7 @@ MOCKABLE_FUNCTION(, JSON_Object*, json_value_get_object, const JSON_Value *, val #define TEST_STRING_HANDLE_DEVICE_SAS ((STRING_HANDLE)0x2) #define TEST_API_VERSION "?api-version=2016-11-14" -#define TEST_IOTHUB_SDK_VERSION "1.2.12" +#define TEST_IOTHUB_SDK_VERSION "1.3.0" static const char* const testUploadtrustedCertificates = "some certificates"; static const char* const TEST_SAS_TOKEN = "test_sas_token"; diff --git a/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/CMakeLists.txt b/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/CMakeLists.txt index 418072e109..8f9e24f4d0 100644 --- a/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/CMakeLists.txt +++ b/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/CMakeLists.txt @@ -45,7 +45,7 @@ if(WIN32) target_link_libraries(${theseTestsName}_dll iothub_test iothub_client - iothub_client_mqtt_transport + iothub_client_mqtt_ws_transport iothub_service_client aziotsharedutil rpcrt4 @@ -58,7 +58,7 @@ if(WIN32) target_link_libraries(${theseTestsName}_exe iothub_test iothub_client - iothub_client_mqtt_transport + iothub_client_mqtt_ws_transport iothub_service_client aziotsharedutil rpcrt4 @@ -91,10 +91,10 @@ else() target_link_libraries(${theseTestsName}_exe iothub_test iothub_client - iothub_client_mqtt_transport + iothub_client_mqtt_ws_transport iothub_service_client aziotsharedutil - iothub_client_mqtt_transport + iothub_client_mqtt_ws_transport ) linkUAMQP(${theseTestsName}_exe) linkMqttLibrary(${theseTestsName}_exe) diff --git a/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/iothubclient_mqtt_ws_ds_e2e.c b/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/iothubclient_mqtt_ws_ds_e2e.c index ef7155a8e9..959ce1ef8a 100644 --- a/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/iothubclient_mqtt_ws_ds_e2e.c +++ b/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/iothubclient_mqtt_ws_ds_e2e.c @@ -5,7 +5,7 @@ #include "iothubclient_common_ds_e2e.h" #include "iothubtransportmqtt.h" -BEGIN_TEST_SUITE(iothubclient_mqtt_ds_e2e) +BEGIN_TEST_SUITE(iothubclient_mqtt_ws_ds_e2e) TEST_SUITE_INITIALIZE(TestClassInitialize) { @@ -27,4 +27,4 @@ TEST_FUNCTION(IoTHub_Reject_Device_Streaming_Request_MQTT_e2e) ds_e2e_receive_device_streaming_request(MQTT_Protocol, false); } -END_TEST_SUITE(iothubclient_mqtt_ds_e2e) +END_TEST_SUITE(iothubclient_mqtt_ws_ds_e2e) diff --git a/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/main.c b/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/main.c index 50e23040af..8ae60708e1 100644 --- a/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/main.c +++ b/iothub_client/tests/iothubclient_mqtt_ws_ds_e2e/main.c @@ -6,6 +6,6 @@ int main(void) { size_t failedTestCount = 0; - RUN_TEST_SUITE(iothubclient_mqtt_ds_e2e, failedTestCount); + RUN_TEST_SUITE(iothubclient_mqtt_ws_ds_e2e, failedTestCount); return failedTestCount; } diff --git a/iothub_client/tests/iothubclientcore_ll_ut/iothub_client_core_ll_ut.c b/iothub_client/tests/iothubclientcore_ll_ut/iothub_client_core_ll_ut.c index 72b40c96d7..ecd8233699 100644 --- a/iothub_client/tests/iothubclientcore_ll_ut/iothub_client_core_ll_ut.c +++ b/iothub_client/tests/iothubclientcore_ll_ut/iothub_client_core_ll_ut.c @@ -198,6 +198,9 @@ static const char* TEST_STRING_VALUE = "Test string value"; #define TEST_DEVICEKEY_TOKEN "SharedAccessKey" #define TEST_DEVICESAS_TOKEN "SharedAccessSignature" #define TEST_PROTOCOL_GATEWAY_HOST_NAME_TOKEN "GatewayHostName" +#define TEST_INVALID_TOKEN1 "InvalidToken1" +#define TEST_INVALID_TOKEN2 "InvalidToken2" + #define TEST_X509 "x509" #define TEST_MODULE_ID_TOKEN "ModuleId" #define TEST_PROVISIONING_TOKEN "UseProvisioning" @@ -462,7 +465,7 @@ static CONSTBUFFER_HANDLE my_CONSTBUFFER_Create(const unsigned char* source, siz return (CONSTBUFFER_HANDLE)my_gballoc_malloc(1); } -static void my_CONSTBUFFER_Destroy(CONSTBUFFER_HANDLE constbufferHandle) +static void my_CONSTBUFFER_DecRef(CONSTBUFFER_HANDLE constbufferHandle) { my_gballoc_free(constbufferHandle); } @@ -916,7 +919,7 @@ TEST_SUITE_INITIALIZE(suite_init) REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_Create, my_CONSTBUFFER_Create); REGISTER_GLOBAL_MOCK_FAIL_RETURN(CONSTBUFFER_Create, NULL); - REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_Destroy, my_CONSTBUFFER_Destroy); + REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_DecRef, my_CONSTBUFFER_DecRef); REGISTER_GLOBAL_MOCK_HOOK(STRING_TOKENIZER_create, my_STRING_TOKENIZER_create); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_TOKENIZER_create, NULL); @@ -1027,27 +1030,26 @@ static void setup_IoTHubClientCore_LL_create_mocks(bool use_device_config, bool { STRICT_EXPECTED_CALL(IoTHubClient_Auth_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); } - - STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); #ifndef DONT_USE_UPLOADTOBLOB - STRICT_EXPECTED_CALL(IoTHubClient_LL_UploadToBlob_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_LL_UploadToBlob_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); #endif /*DONT_USE_UPLOADTOBLOB*/ #ifdef USE_EDGE_MODULES - if (is_edge_module) - { - STRICT_EXPECTED_CALL(IoTHubClient_EdgeHandle_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); - } + if (is_edge_module) + { + STRICT_EXPECTED_CALL(IoTHubClient_EdgeHandle_Create(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + } #else - (void)is_edge_module; + (void)is_edge_module; #endif /*USE_EDGE_MODULES*/ - STRICT_EXPECTED_CALL(tickcounter_create()); - STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_Register(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_SetRetryPolicy(IGNORED_PTR_ARG, TEST_RETRY_POLICY, 0)); + STRICT_EXPECTED_CALL(tickcounter_create()); + STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_Register(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_SetRetryPolicy(IGNORED_PTR_ARG, TEST_RETRY_POLICY, 0)); } static void setup_IoTHubClientCore_LL_sendreportedstate_mocks() @@ -1139,7 +1141,7 @@ static void setup_IoTHubClientCore_LL_createfromconnectionstring_2_mocks(const c STRICT_EXPECTED_CALL(gballoc_free(IGNORED_NUM_ARG)).IgnoreArgument_ptr(); } -static void setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(const char* device_token, const char* token_value) +static void setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(const char* device_token, const char* token_value, bool include_invalid_tokens) { STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); @@ -1175,6 +1177,17 @@ static void setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(const cha STRICT_EXPECTED_CALL(STRING_clone(IGNORED_PTR_ARG)).IgnoreArgument(1); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)).SetReturn(token_value).CallCannotFail(); // 25 + if (include_invalid_tokens) + { + EXPECTED_CALL(STRING_TOKENIZER_get_next_token(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + EXPECTED_CALL(STRING_TOKENIZER_get_next_token(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)).SetReturn(TEST_INVALID_TOKEN1).CallCannotFail(); + + EXPECTED_CALL(STRING_TOKENIZER_get_next_token(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + EXPECTED_CALL(STRING_TOKENIZER_get_next_token(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)).SetReturn(TEST_INVALID_TOKEN2).CallCannotFail(); + } + /* loop exit */ // Mark CallCannotFail because this is final pass through loop, expected to bail out, so shouldn't failure test it. EXPECTED_CALL(STRING_TOKENIZER_get_next_token(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)).SetReturn(__LINE__).CallCannotFail(); // 26 @@ -1183,7 +1196,7 @@ static void setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(const cha setup_IoTHubClientCore_LL_create_mocks(false, false); - EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); + EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); // 38 EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); @@ -1213,7 +1226,7 @@ TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_DeviceKey_fail ASSERT_ARE_EQUAL(int, 0, negativeTestsInitResult); //arrange - setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICEKEY_TOKEN, TEST_STRING_VALUE); + setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICEKEY_TOKEN, TEST_STRING_VALUE, false); umock_c_negative_tests_snapshot(); @@ -1254,7 +1267,7 @@ TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_DeviceKey_fail TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_DeviceKey_succeeds) { //arrange - setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICEKEY_TOKEN, TEST_STRING_VALUE); + setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICEKEY_TOKEN, TEST_STRING_VALUE, false); //act IOTHUB_CLIENT_CORE_LL_HANDLE result = IoTHubClientCore_LL_CreateFromConnectionString(TEST_CHAR, provideFAKE); @@ -1289,7 +1302,7 @@ TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_provisioning_s TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_DeviceSasToken_succeeds) { //arrange - setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICESAS_TOKEN, TEST_STRING_VALUE); + setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICESAS_TOKEN, TEST_STRING_VALUE, false); //act IOTHUB_CLIENT_CORE_LL_HANDLE result = IoTHubClientCore_LL_CreateFromConnectionString(TEST_CHAR, provideFAKE); @@ -1302,6 +1315,26 @@ TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_DeviceSasToken IoTHubClientCore_LL_Destroy(result); } +/* Tests_SRS_IoTHubClientCore_LL_12_011: [IoTHubClientCore_LL_CreateFromConnectionString shall call into the IoTHubClientCore_LL_Create API with the current structure and returns with the return value of it] */ +/* Tests_SRS_IoTHubClientCore_LL_12_010: [IoTHubClientCore_LL_CreateFromConnectionString shall fill up the IOTHUB_CLIENT_CONFIG structure using the following mapping: iotHubName = Name, iotHubSuffix = Suffix, deviceId = DeviceId, deviceKey = SharedAccessKey or deviceSasToken = SharedAccessSignature] */ +/* Tests_SRS_IoTHubClientCore_LL_02_092: [ IoTHubClientCore_LL_CreateFomConnectionString shall create a IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE from IOTHUB_CLIENT_CONFIG. ]*/ +TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_with_DeviceSasToken_with_invalid_tokens_succeeds) +{ + //arrange + setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICESAS_TOKEN, TEST_STRING_VALUE, true); + + //act + IOTHUB_CLIENT_CORE_LL_HANDLE result = IoTHubClientCore_LL_CreateFromConnectionString(TEST_CHAR, provideFAKE); + + ///assert + ASSERT_ARE_NOT_EQUAL(void_ptr, NULL, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + ///cleanup + IoTHubClientCore_LL_Destroy(result); +} + + /* Tests_SRS_IoTHubClientCore_LL_04_001: [IoTHubClientCore_LL_CreateFromConnectionString shall verify the existence of key/value pair GatewayHostName. If it does exist it shall pass the value to IoTHubClientCore_LL_Create API.] */ TEST_FUNCTION(IoTHubClientCore_LL_CreateFromConnectionString_withGatewayHostName_succeeds) { @@ -4680,7 +4713,7 @@ TEST_FUNCTION(IoTHubClientCore_LL_ReportedStateComplete_succeed) STRICT_EXPECTED_CALL(DList_RemoveEntryList(IGNORED_PTR_ARG)) .IgnoreArgument(1); - STRICT_EXPECTED_CALL(CONSTBUFFER_Destroy(IGNORED_PTR_ARG)) + STRICT_EXPECTED_CALL(CONSTBUFFER_DecRef(IGNORED_PTR_ARG)) .IgnoreArgument(1); STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)) @@ -6766,7 +6799,7 @@ static void set_expected_calls_for_IoTHubClientCore_LL_CreateFromEnvironment_for STRICT_EXPECTED_CALL(environment_get_variable(IGNORED_PTR_ARG)).SetReturn(TEST_EDGEHUB_CONNECTIONSTRING); STRICT_EXPECTED_CALL(environment_get_variable(IGNORED_PTR_ARG)).SetReturn(TEST_EDGEHUB_CACERTIFICATEFILE); - setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICEKEY_TOKEN, TEST_STRING_VALUE); + setup_IoTHubClientCore_LL_createfromconnectionstring_mocks(TEST_DEVICEKEY_TOKEN, TEST_STRING_VALUE, false); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_TrustBundle(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(FAKE_IoTHubTransport_SetOption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); diff --git a/iothub_client/tests/iothubclientcore_ut/iothubclientcore_ut.c b/iothub_client/tests/iothubclientcore_ut/iothubclientcore_ut.c index 541ba23abb..d6be690eb0 100644 --- a/iothub_client/tests/iothubclientcore_ut/iothubclientcore_ut.c +++ b/iothub_client/tests/iothubclientcore_ut/iothubclientcore_ut.c @@ -4451,7 +4451,6 @@ TEST_FUNCTION(IoTHubClientCore_SetStreamRequestCallback_succeed) ASSERT_ARE_EQUAL(IOTHUB_CLIENT_RESULT, IOTHUB_CLIENT_OK, result); // cleanup - free(my_malloc_items[--my_malloc_count]); IoTHubClientCore_Destroy(iothub_handle); } diff --git a/iothub_client/tests/iothubmessage_ut/iothubmessage_ut.c b/iothub_client/tests/iothubmessage_ut/iothubmessage_ut.c index bdf0baa07f..bcb4ff6517 100644 --- a/iothub_client/tests/iothubmessage_ut/iothubmessage_ut.c +++ b/iothub_client/tests/iothubmessage_ut/iothubmessage_ut.c @@ -1366,8 +1366,8 @@ TEST_FUNCTION(IoTHubMessage_SetContentEncodingSystemProperty_Not_NULL_SUCCEED) IOTHUB_MESSAGE_RESULT result = IoTHubMessage_SetContentEncodingSystemProperty(h, TEST_CONTENT_ENCODING); umock_c_reset_all_calls(); - STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, TEST_CONTENT_ENCODING)); + STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); //act result = IoTHubMessage_SetContentEncodingSystemProperty(h, TEST_CONTENT_ENCODING); @@ -2068,6 +2068,108 @@ TEST_FUNCTION(IoTHubMessage_GetConnectionDeviceId_SUCCEED) get_string_succeeds_impl(IoTHubMessage_SetConnectionDeviceId, IoTHubMessage_GetConnectionDeviceId, TEST_CONNECTION_DEVICE_ID); } +TEST_FUNCTION(IoTHubMessage_SetAsSecurityMessage_handle_NULL_fail) +{ + //arrange + + //act + IOTHUB_MESSAGE_RESULT result = IoTHubMessage_SetAsSecurityMessage(NULL); + + //assert + ASSERT_ARE_NOT_EQUAL(int, IOTHUB_MESSAGE_OK, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup +} + +TEST_FUNCTION(IoTHubMessage_SetAsSecurityMessage_Succeed) +{ + //arrange + IOTHUB_MESSAGE_HANDLE h = IoTHubMessage_CreateFromByteArray(c, 1); + umock_c_reset_all_calls(); + + STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + //act + IOTHUB_MESSAGE_RESULT result = IoTHubMessage_SetAsSecurityMessage(h); + + //assert + ASSERT_ARE_EQUAL(int, IOTHUB_MESSAGE_OK, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + IoTHubMessage_Destroy(h); +} + +TEST_FUNCTION(IoTHubMessage_Clone_SecurityMessage_Succeed) +{ + //arrange + IOTHUB_MESSAGE_HANDLE h = IoTHubMessage_CreateFromByteArray(c, 1); + IoTHubMessage_SetAsSecurityMessage(h); + umock_c_reset_all_calls(); + + //act + IOTHUB_MESSAGE_HANDLE clone_msg = IoTHubMessage_Clone(h); + bool result = IoTHubMessage_IsSecurityMessage(h); + + //assert + ASSERT_IS_TRUE(result); + + //cleanup + IoTHubMessage_Destroy(h); + IoTHubMessage_Destroy(clone_msg); +} + +TEST_FUNCTION(IoTHubMessage_IsSecurityMessage_handle_NULL_fail) +{ + //arrange + umock_c_reset_all_calls(); + + //act + bool result = IoTHubMessage_IsSecurityMessage(NULL); + + //assert + ASSERT_IS_FALSE(result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup +} + +TEST_FUNCTION(IoTHubMessage_IsSecurityMessage_true_Succeed) +{ + //arrange + IOTHUB_MESSAGE_HANDLE h = IoTHubMessage_CreateFromByteArray(c, 1); + IoTHubMessage_SetAsSecurityMessage(h); + umock_c_reset_all_calls(); + + //act + bool result = IoTHubMessage_IsSecurityMessage(h); + + //assert + ASSERT_IS_TRUE(result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + IoTHubMessage_Destroy(h); +} + +TEST_FUNCTION(IoTHubMessage_IsSecurityMessage_false_Succeed) +{ + //arrange + IOTHUB_MESSAGE_HANDLE h = IoTHubMessage_CreateFromByteArray(c, 1); + umock_c_reset_all_calls(); + + //act + bool result = IoTHubMessage_IsSecurityMessage(h); + + //assert + ASSERT_IS_FALSE(result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + IoTHubMessage_Destroy(h); +} + END_TEST_SUITE(iothubmessage_ut) diff --git a/iothub_client/tests/iothubtr_amqp_twin_msgr_ut/iothubtr_amqp_twin_msgr_ut.c b/iothub_client/tests/iothubtr_amqp_twin_msgr_ut/iothubtr_amqp_twin_msgr_ut.c index 8fb7ec408c..4a0b2f04bc 100644 --- a/iothub_client/tests/iothubtr_amqp_twin_msgr_ut/iothubtr_amqp_twin_msgr_ut.c +++ b/iothub_client/tests/iothubtr_amqp_twin_msgr_ut/iothubtr_amqp_twin_msgr_ut.c @@ -264,9 +264,9 @@ extern "C" CONSTBUFFER_HANDLE real_CONSTBUFFER_Create(const unsigned char* source, size_t size); CONSTBUFFER_HANDLE real_CONSTBUFFER_CreateFromBuffer(BUFFER_HANDLE buffer); - CONSTBUFFER_HANDLE real_CONSTBUFFER_Clone(CONSTBUFFER_HANDLE constbufferHandle); + void real_CONSTBUFFER_IncRef(CONSTBUFFER_HANDLE constbufferHandle); const CONSTBUFFER* real_CONSTBUFFER_GetContent(CONSTBUFFER_HANDLE constbufferHandle); - void real_CONSTBUFFER_Destroy(CONSTBUFFER_HANDLE constbufferHandle); + void real_CONSTBUFFER_DecRef(CONSTBUFFER_HANDLE constbufferHandle); #ifdef __cplusplus } @@ -453,7 +453,7 @@ static void set_expected_calls_for_twin_messenger_create(TWIN_MESSENGER_CONFIG* static void set_twin_messenger_report_state_async_expected_calls(CONSTBUFFER_HANDLE report, time_t current_time) { STRICT_EXPECTED_CALL(malloc(IGNORED_NUM_ARG)); - STRICT_EXPECTED_CALL(CONSTBUFFER_Clone(report)); + STRICT_EXPECTED_CALL(CONSTBUFFER_IncRef(report)); STRICT_EXPECTED_CALL(get_time(NULL)) .SetReturn(current_time); STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -484,7 +484,7 @@ static void set_process_timeouts_expected_calls(time_t current_time, size_t numb for (i = 0; i < number_of_expired_pending_patches; i++) { STRICT_EXPECTED_CALL(get_difftime(current_time, IGNORED_NUM_ARG)).SetReturn(10000000); // Simulate it's expired for sure. - STRICT_EXPECTED_CALL(CONSTBUFFER_Destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(CONSTBUFFER_DecRef(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG)); } @@ -622,7 +622,7 @@ static void set_twin_messenger_do_work_expected_calls(DOWORK_TEST_PROFILE* dwtp) set_send_twin_operation_request_expected_calls(dwtp->current_time); - STRICT_EXPECTED_CALL(CONSTBUFFER_Destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(CONSTBUFFER_DecRef(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG)); dwtp->number_of_pending_patches--; @@ -667,7 +667,7 @@ static void send_one_report_patch(TWIN_MESSENGER_HANDLE handle, time_t current_t set_twin_messenger_report_state_async_expected_calls(report, current_time); (void)twin_messenger_report_state_async(handle, report, TEST_on_report_state_complete_callback, NULL); - real_CONSTBUFFER_Destroy(report); + real_CONSTBUFFER_DecRef(report); } static void crank_twin_messenger_do_work(TWIN_MESSENGER_HANDLE handle, TWIN_MESSENGER_CONFIG* config, DOWORK_TEST_PROFILE* dwtp) @@ -708,8 +708,8 @@ static void register_global_mock_hooks() REGISTER_GLOBAL_MOCK_HOOK(malloc, TEST_malloc); REGISTER_GLOBAL_MOCK_HOOK(free, TEST_free); REGISTER_GLOBAL_MOCK_HOOK(amqp_messenger_create, TEST_amqp_messenger_create); - REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_Clone, real_CONSTBUFFER_Clone); - REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_Destroy, real_CONSTBUFFER_Destroy); + REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_IncRef, real_CONSTBUFFER_IncRef); + REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_DecRef, real_CONSTBUFFER_DecRef); REGISTER_GLOBAL_MOCK_HOOK(CONSTBUFFER_GetContent, real_CONSTBUFFER_GetContent); REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_create, real_singlylinkedlist_create); REGISTER_GLOBAL_MOCK_HOOK(singlylinkedlist_destroy, real_singlylinkedlist_destroy); @@ -1086,7 +1086,7 @@ TEST_FUNCTION(twin_msgr_report_state_async_NULL_handle) ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); // cleanup - real_CONSTBUFFER_Destroy(report); + real_CONSTBUFFER_DecRef(report); } // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_022: [If `twin_msgr_handle` or `data` are NULL, twin_messenger_report_state_async() shall fail and return a non-zero value] @@ -1110,7 +1110,7 @@ TEST_FUNCTION(twin_msgr_report_state_async_NULL_data) } // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_023: [twin_messenger_report_state_async() shall allocate memory for a TWIN_PATCH_OPERATION_CONTEXT structure (aka `twin_op_ctx`)] -// Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_025: [`twin_op_ctx` shall have a copy of `data`] +// Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_025: [`twin_op_ctx` shall increment the reference count for `data` and store it.] // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_027: [`twin_op_ctx->time_enqueued` shall be set using get_time] // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_029: [`twin_op_ctx` shall be added to `twin_msgr->pending_patches` using singlylinkedlist_add()] // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_032: [If no failures occur, twin_messenger_report_state_async() shall return zero] @@ -1135,12 +1135,11 @@ TEST_FUNCTION(twin_msgr_report_state_async_success) ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); // cleanup - real_CONSTBUFFER_Destroy(report); + real_CONSTBUFFER_DecRef(report); twin_messenger_destroy(handle); } // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_024: [If malloc() fails, twin_messenger_report_state_async() shall fail and return a non-zero value] -// Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_026: [If `data` fails to be copied, twin_messenger_report_state_async() shall fail and return a non-zero value] // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_028: [If `twin_op_ctx->time_enqueued` fails to be set, twin_messenger_report_state_async() shall fail and return a non-zero value] // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_030: [If singlylinkedlist_add() fails, twin_messenger_report_state_async() shall fail and return a non-zero value] // Tests_IOTHUBTRANSPORT_AMQP_TWIN_MESSENGER_09_031: [If any failure occurs, twin_messenger_report_state_async() shall free any memory it has allocated] @@ -1164,21 +1163,24 @@ TEST_FUNCTION(twin_msgr_report_state_async_failure_checks) size_t i; for (i = 0; i < umock_c_negative_tests_call_count(); i++) { - // arrange - char error_msg[64]; + if (umock_c_negative_tests_can_call_fail(i)) + { + // arrange + char error_msg[64]; - umock_c_negative_tests_reset(); - umock_c_negative_tests_fail_call(i); + umock_c_negative_tests_reset(); + umock_c_negative_tests_fail_call(i); - int result = twin_messenger_report_state_async(handle, report, TEST_on_report_state_complete_callback, NULL); + int result = twin_messenger_report_state_async(handle, report, TEST_on_report_state_complete_callback, NULL); - // assert - sprintf(error_msg, "On failed call %lu", (unsigned long)i); - ASSERT_ARE_NOT_EQUAL(int, 0, result, error_msg); + // assert + sprintf(error_msg, "On failed call %lu", (unsigned long)i); + ASSERT_ARE_NOT_EQUAL(int, 0, result, error_msg); + } } // cleanup - real_CONSTBUFFER_Destroy(report); + real_CONSTBUFFER_DecRef(report); twin_messenger_destroy(handle); umock_c_negative_tests_deinit(); } diff --git a/iothub_client/tests/iothubtransport_amqp_common_ut/iothubtransport_amqp_common_ut.c b/iothub_client/tests/iothubtransport_amqp_common_ut/iothubtransport_amqp_common_ut.c index fdcd0bdff9..24060126f1 100644 --- a/iothub_client/tests/iothubtransport_amqp_common_ut/iothubtransport_amqp_common_ut.c +++ b/iothub_client/tests/iothubtransport_amqp_common_ut/iothubtransport_amqp_common_ut.c @@ -4526,8 +4526,8 @@ TEST_FUNCTION(ConnectionStatusCallBack_UNAUTH_no_network) crank_transport_ready_after_create(handle, &TEST_waitingToSend, 0, false, true, 1, TEST_current_time, false, false); umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(Transport_ConnectionStatusCallBack(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_NO_NETWORK, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(get_time(NULL)).SetReturn(TEST_current_time); - STRICT_EXPECTED_CALL(Transport_ConnectionStatusCallBack(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_NO_NETWORK, IGNORED_PTR_ARG)); // act @@ -4560,6 +4560,7 @@ TEST_FUNCTION(ConnectionStatusCallBack_UNAUTH_retry_expired) umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(Transport_ConnectionStatusCallBack(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_NO_NETWORK, IGNORED_PTR_ARG)); RETRY_ACTION retry_action = RETRY_ACTION_STOP_RETRYING; STRICT_EXPECTED_CALL(retry_control_should_retry(TEST_RETRY_CONTROL_HANDLE, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer_retry_action(&retry_action, sizeof(RETRY_ACTION)); diff --git a/iothub_client/tests/iothubtransport_amqp_streaming_ut/iothubtransport_amqp_streaming_ut.c b/iothub_client/tests/iothubtransport_amqp_streaming_ut/iothubtransport_amqp_streaming_ut.c index 6af93fec76..781366a5ab 100644 --- a/iothub_client/tests/iothubtransport_amqp_streaming_ut/iothubtransport_amqp_streaming_ut.c +++ b/iothub_client/tests/iothubtransport_amqp_streaming_ut/iothubtransport_amqp_streaming_ut.c @@ -363,7 +363,7 @@ static void set_expected_calls_for_amqp_streaming_client_create(AMQP_STREAMING_C static void set_twin_messenger_report_state_async_expected_calls(CONSTBUFFER_HANDLE report, time_t current_time) { STRICT_EXPECTED_CALL(malloc(IGNORED_NUM_ARG)); - STRICT_EXPECTED_CALL(CONSTBUFFER_Clone(report)); + STRICT_EXPECTED_CALL(CONSTBUFFER_IncRef(report)); STRICT_EXPECTED_CALL(get_time(NULL)) .SetReturn(current_time); STRICT_EXPECTED_CALL(singlylinkedlist_add(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -456,7 +456,7 @@ static void set_expected_calls_for_process_timeouts(time_t current_time, size_t for (i = 0; i < number_of_expired_pending_patches; i++) { STRICT_EXPECTED_CALL(get_difftime(current_time, IGNORED_NUM_ARG)).SetReturn(10000000); // Simulate it's expired for sure. - STRICT_EXPECTED_CALL(CONSTBUFFER_Destroy(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(CONSTBUFFER_DecRef(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG)); } @@ -590,6 +590,8 @@ static void set_expected_calls_for_destroy_parsed_info() static void set_expected_calls_for_on_amqp_message_received_callback() { + STRICT_EXPECTED_CALL(amqp_messenger_destroy_disposition_info(IGNORED_PTR_ARG)); + set_expected_calls_for_parse_amqp_message(); set_expected_calls_for_create_stream_c2d_request_from_parsed_info(); diff --git a/iothub_client/tests/iothubtransport_mqtt_common_ut/iothubtransport_mqtt_common_ut.c b/iothub_client/tests/iothubtransport_mqtt_common_ut/iothubtransport_mqtt_common_ut.c index 5464e45795..2b414d02f0 100644 --- a/iothub_client/tests/iothubtransport_mqtt_common_ut/iothubtransport_mqtt_common_ut.c +++ b/iothub_client/tests/iothubtransport_mqtt_common_ut/iothubtransport_mqtt_common_ut.c @@ -931,6 +931,8 @@ TEST_SUITE_INITIALIZE(suite_init) REGISTER_GLOBAL_MOCK_RETURN(IoTHubMessage_SetInputName, IOTHUB_MESSAGE_OK); REGISTER_GLOBAL_MOCK_FAIL_RETURN(IoTHubMessage_SetInputName, IOTHUB_MESSAGE_ERROR); + REGISTER_GLOBAL_MOCK_RETURN(IoTHubMessage_IsSecurityMessage, false); + REGISTER_GLOBAL_MOCK_RETURN(IoTHubMessage_SetConnectionDeviceId, IOTHUB_MESSAGE_OK); REGISTER_GLOBAL_MOCK_FAIL_RETURN(IoTHubMessage_SetConnectionDeviceId, IOTHUB_MESSAGE_ERROR); @@ -1232,6 +1234,7 @@ static void setup_initialize_connection_mocks() static void setup_subscribe_devicetwin_dowork_mocks() { STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mqtt_client_subscribe(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); @@ -1247,6 +1250,7 @@ static void setup_subscribe_devicetwin_dowork_mocks() static void setup_IoTHubTransport_MQTT_Common_DoWork_mocks() { STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)).SetReturn(TEST_MQTT_MSG_TOPIC); EXPECTED_CALL(mqtt_client_subscribe(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); @@ -1261,6 +1265,7 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_mocks() static void setup_IoTHubTransport_MQTT_Common_DoWork_emtpy_msg_mocks(void) { STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetContentType(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetString(IGNORED_PTR_ARG)).SetReturn(""); @@ -1271,6 +1276,7 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_emtpy_msg_mocks(void) //Add Properties STRICT_EXPECTED_CALL(IoTHubMessage_Properties(IGNORED_PTR_ARG)); EXPECTED_CALL(Map_GetInternals(TEST_MESSAGE_PROP_MAP, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetCorrelationId(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetMessageId(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetContentTypeSystemProperty(IGNORED_PTR_ARG)); @@ -1313,11 +1319,13 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_resend_events_mocks( const char* diag_id, const char* creation_time_utc, bool auto_urlencode, - const char* output_name) + const char* output_name, + bool security_msg) { TEST_DIAG_DATA.diagnosticId = (char*)diag_id; TEST_DIAG_DATA.diagnosticCreationTimeUtc = (char*)creation_time_utc; STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetContentType(msg_handle)); if (msg_handle == TEST_IOTHUB_MSG_STRING) @@ -1360,6 +1368,13 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_resend_events_mocks( } } } + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)).SetReturn(security_msg); + if (security_msg) + { + STRICT_EXPECTED_CALL(URL_EncodeString(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); + } STRICT_EXPECTED_CALL(IoTHubMessage_GetCorrelationId(IGNORED_PTR_ARG)).SetReturn(core_id); if (auto_urlencode && (core_id != NULL)) { @@ -1453,11 +1468,13 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks( const char* diag_id, const char* creation_time_utc, bool auto_urlencode, - const char* output_name) + const char* output_name, + bool security_msg) { TEST_DIAG_DATA.diagnosticId = (char*)diag_id; TEST_DIAG_DATA.diagnosticCreationTimeUtc = (char*)creation_time_utc; STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetContentType(msg_handle)); if (msg_handle == TEST_IOTHUB_MSG_STRING) @@ -1500,6 +1517,7 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks( } } } + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)).SetReturn(security_msg); STRICT_EXPECTED_CALL(IoTHubMessage_GetCorrelationId(IGNORED_PTR_ARG)).SetReturn(core_id); if (auto_urlencode && (core_id != NULL)) { @@ -1522,17 +1540,25 @@ static void setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks( STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); } STRICT_EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(IGNORED_PTR_ARG)).SetReturn(content_encoding); - if (auto_urlencode && (content_encoding != NULL)) + if (security_msg || (auto_urlencode && (content_encoding != NULL))) { STRICT_EXPECTED_CALL(URL_EncodeString(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); } + STRICT_EXPECTED_CALL(IoTHubMessage_GetDistributedTracingSystemProperty(IGNORED_PTR_ARG)).SetReturn(DISTRIBUTED_TRACING_TEST_TRACESTATE); STRICT_EXPECTED_CALL(URL_EncodeString(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); + if (security_msg) + { + STRICT_EXPECTED_CALL(URL_EncodeString(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); + } + STRICT_EXPECTED_CALL(IoTHubMessage_GetDiagnosticPropertyData(IGNORED_PTR_ARG)).SetReturn(&TEST_DIAG_DATA); bool validMessage = true; @@ -1694,6 +1720,20 @@ static void setup_message_recv_msg_callback_mocks() STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); } +static TRANSPORT_LL_HANDLE setup_iothub_mqtt_connection(IOTHUBTRANSPORT_CONFIG* config) +{ + TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + setup_initialize_connection_mocks(); + IoTHubTransport_MQTT_Common_DoWork(handle); + CONNECT_ACK connack; + connack.isSessionPresent = true; + connack.returnCode = CONNECTION_ACCEPTED; + g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_CONNACK, &connack, g_callbackCtx); + IoTHubTransport_MQTT_Common_DoWork(handle); + + return handle; +} + static void setup_message_recv_callback_STREAM_C2D_REQUEST_mocks( char** topicLevels, size_t topicLevelCount, @@ -1776,6 +1816,7 @@ static XIO_HANDLE get_IO_transport_fail(const char* fully_qualified_name, const static void setup_subscribe_inputqueue_dowork_mocks() { STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mqtt_client_subscribe(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); @@ -2198,23 +2239,20 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_Destroy_One_Message_Ack_succeeds) IOTHUBTRANSPORT_CONFIG config ={ 0 }; SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); - QOS_VALUE QosValue[] ={ DELIVER_AT_LEAST_ONCE }; - SUBSCRIBE_ACK suback; - suback.packetId = 1234; - suback.qosCount = 1; - suback.qosReturn = QosValue; - IOTHUB_MESSAGE_LIST message1; memset(&message1, 0, sizeof(IOTHUB_MESSAGE_LIST) ); message1.messageHandle = TEST_IOTHUB_MSG_BYTEARRAY; DList_InsertTailList(config.waitingToSend, &(message1.entry)); - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); - g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_SUBSCRIBE_ACK, &suback, g_callbackCtx); - IoTHubTransport_MQTT_Common_DoWork(handle); + + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); + IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); + STRICT_EXPECTED_CALL(mqtt_client_disconnect(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(ThreadAPI_Sleep(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_destroy(IGNORED_PTR_ARG)); EXPECTED_CALL(DList_IsListEmpty(IGNORED_PTR_ARG)); EXPECTED_CALL(DList_RemoveHeadList(IGNORED_PTR_ARG)); @@ -3942,21 +3980,23 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_send_get_twin_succeed) suback.qosCount = 1; suback.qosReturn = QosValue; - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_SUBSCRIBE_ACK, &suback, g_callbackCtx); IoTHubTransport_MQTT_Common_DoWork(handle); // Request the Twin content umock_c_reset_all_calls(); - STRICT_EXPECTED_CALL(malloc(IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(DList_InsertTailList(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); (void)IoTHubTransport_MQTT_Common_GetTwinAsync(handle, on_get_device_twin_completed_callback, (void*)0x4445); // Send the GET request umock_c_reset_all_calls(); - STRICT_EXPECTED_CALL(retry_control_should_retry(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(DList_RemoveEntryList(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); // STRING_construct_sprintf @@ -4002,7 +4042,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_send_get_twin_succeed) STRICT_EXPECTED_CALL(mqttmessage_getApplicationMsg(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(DList_RemoveEntryList(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); // act g_fnMqttMsgRecv(TEST_MQTT_MESSAGE_HANDLE, g_callbackCtx); @@ -4091,21 +4131,14 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_Retry_Policy_Connection_Break_W IOTHUBTRANSPORT_CONFIG config = { 0 }; SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); IoTHubTransport_MQTT_Common_SetRetryPolicy(handle, TEST_RETRY_POLICY, TEST_RETRY_TIMEOUT_SECS); - setup_initialize_connection_mocks(); - IoTHubTransport_MQTT_Common_DoWork(handle); - CONNECT_ACK connack; - connack.isSessionPresent = true; - connack.returnCode = CONNECTION_ACCEPTED; - g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_CONNACK, &connack, g_callbackCtx); umock_c_reset_all_calls(); /*First Do_Work*/ RETRY_ACTION retry_action = RETRY_ACTION_RETRY_LATER; EXPECTED_CALL(retry_control_should_retry(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer_retry_action(&retry_action, sizeof(retry_action)); - STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); // removeExpiredPendingGetTwinRequests STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -4115,7 +4148,6 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_Retry_Policy_Connection_Break_W /*Second Do_Work*/ EXPECTED_CALL(retry_control_should_retry(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer_retry_action(&retry_action, sizeof(retry_action)); - STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); // removeExpiredPendingGetTwinRequests STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -4152,16 +4184,9 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_Retry_Policy_Connection_Break_R IOTHUBTRANSPORT_CONFIG config = { 0 }; SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); IoTHubTransport_MQTT_Common_SetRetryPolicy(handle, TEST_RETRY_POLICY, TEST_RETRY_TIMEOUT_SECS); - setup_initialize_connection_mocks(); - IoTHubTransport_MQTT_Common_DoWork(handle); - CONNECT_ACK connack; - connack.isSessionPresent = true; - connack.returnCode = CONNECTION_ACCEPTED; - g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_CONNACK, &connack, g_callbackCtx); - connack.isSessionPresent = false; - connack.returnCode = CONN_REFUSED_SERVER_UNAVAIL; + /* Break Connection */ g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_DISCONNECT, NULL, g_callbackCtx); @@ -4180,9 +4205,15 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_Retry_Policy_Connection_Break_R EXPECTED_CALL(retry_control_should_retry(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer_retry_action(&retry_action, sizeof(retry_action)); - STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); + + if (counter == 30) + { + STRICT_EXPECTED_CALL(Transport_ConnectionStatusCallBack(IOTHUB_CLIENT_CONNECTION_UNAUTHENTICATED, IOTHUB_CLIENT_CONNECTION_RETRY_EXPIRED, IGNORED_PTR_ARG)); + } + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); // removeExpiredPendingGetTwinRequests + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); // removeExpiredGetTwinRequestsPendingAck STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -4203,14 +4234,9 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_Retry_Policy_Connection_Break_2 IOTHUBTRANSPORT_CONFIG config = { 0 }; SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); IoTHubTransport_MQTT_Common_SetRetryPolicy(handle, TEST_RETRY_POLICY, TEST_RETRY_TIMEOUT_SECS); - setup_initialize_connection_mocks(); - IoTHubTransport_MQTT_Common_DoWork(handle); CONNECT_ACK connack; - connack.isSessionPresent = true; - connack.returnCode = CONNECTION_ACCEPTED; - g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_CONNACK, &connack, g_callbackCtx); connack.isSessionPresent = false; connack.returnCode = CONN_REFUSED_UNKNOWN; /* Break Connection */ @@ -4221,7 +4247,6 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_Retry_Policy_Connection_Break_2 RETRY_ACTION retry_action = RETRY_ACTION_RETRY_LATER; EXPECTED_CALL(retry_control_should_retry(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer_retry_action(&retry_action, sizeof(retry_action)); - STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); // removeExpiredPendingGetTwinRequests STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -4541,7 +4566,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_succeeds) IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -4582,6 +4607,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_get_item_fails) umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetContentType(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubMessage_GetString(IGNORED_PTR_ARG)).SetReturn(NULL); @@ -4607,6 +4633,63 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_get_item_fails) IoTHubTransport_MQTT_Common_Destroy(handle); } +TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_x509_no_expire_success) +{ + // arrange + IOTHUBTRANSPORT_CONFIG config = { 0 }; + SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); + + QOS_VALUE QosValue[] = { DELIVER_AT_LEAST_ONCE }; + SUBSCRIBE_ACK suback; + suback.packetId = 1234; + suback.qosCount = 1; + suback.qosReturn = QosValue; + + IOTHUB_MESSAGE_LIST message1; + memset(&message1, 0, sizeof(IOTHUB_MESSAGE_LIST)); + message1.messageHandle = TEST_IOTHUB_MSG_STRING; + + DList_InsertTailList(config.waitingToSend, &(message1.entry)); + TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + + CONNECT_ACK connack = { true, CONNECTION_ACCEPTED }; + g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_CONNACK, &connack, g_callbackCtx); + // Reset the calls to make sure we're mocket the following calls + umock_c_reset_all_calls(); + + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)).SetReturn(IOTHUB_CREDENTIAL_TYPE_X509); + // DoWork to process the CONNACK call + IoTHubTransport_MQTT_Common_DoWork(handle); + umock_c_reset_all_calls(); + + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)).SetReturn(IOTHUB_CREDENTIAL_TYPE_X509); + + STRICT_EXPECTED_CALL(IoTHubMessage_GetContentType(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubMessage_GetString(IGNORED_PTR_ARG)).SetReturn(NULL); + + EXPECTED_CALL(DList_RemoveEntryList(IGNORED_PTR_ARG)); + EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); + EXPECTED_CALL(DList_InsertTailList(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + EXPECTED_CALL(Transport_SendComplete_Callback(IGNORED_PTR_ARG, IOTHUB_CLIENT_CONFIRMATION_ERROR, transport_cb_ctx)); + EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + // removeExpiredPendingGetTwinRequests + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + // removeExpiredGetTwinRequestsPendingAck + STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + // act + IoTHubTransport_MQTT_Common_DoWork(handle); + + //assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + IoTHubTransport_MQTT_Common_Destroy(handle); +} + TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_empty_item_succeeds) { // arrange @@ -4647,6 +4730,42 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_empty_item_succeeds) IoTHubTransport_MQTT_Common_Destroy(handle); } +TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_security_msg_succeeds) +{ + // arrange + IOTHUBTRANSPORT_CONFIG config = { 0 }; + SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); + + QOS_VALUE QosValue[] = { DELIVER_AT_LEAST_ONCE }; + SUBSCRIBE_ACK suback; + suback.packetId = 1234; + suback.qosCount = 1; + suback.qosReturn = QosValue; + + IOTHUB_MESSAGE_LIST message1; + memset(&message1, 0, sizeof(IOTHUB_MESSAGE_LIST)); + message1.messageHandle = TEST_IOTHUB_MSG_STRING; + + DList_InsertTailList(config.waitingToSend, &(message1.entry)); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); + + g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_SUBSCRIBE_ACK, &suback, g_callbackCtx); + setup_initialize_connection_mocks(); + IoTHubTransport_MQTT_Common_DoWork(handle); + umock_c_reset_all_calls(); + + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, NULL, NULL, NULL, "json/application", NULL, NULL, false, NULL, true); + + // act + IoTHubTransport_MQTT_Common_DoWork(handle); + + //assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + IoTHubTransport_MQTT_Common_Destroy(handle); +} + TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_fail) { // arrange @@ -4672,7 +4791,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_fail) IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false); umock_c_negative_tests_snapshot(); size_t calls_cannot_fail[] = { 4 }; @@ -4736,7 +4855,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_with_properti IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -4782,7 +4901,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_with_2_proper IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -4830,7 +4949,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_with_properti IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, true, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -4878,7 +4997,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_with_2_proper IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, true, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks((const char* const**)&keys, (const char* const**)&values, propCount, TEST_IOTHUB_MSG_BYTEARRAY, false, NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -4961,7 +5080,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_resend_message_succeeds) umock_c_reset_all_calls(); g_current_ms += 5*60*1000; - setup_IoTHubTransport_MQTT_Common_DoWork_resend_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_resend_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -5015,6 +5134,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_message_timeout_succeeds) g_current_ms += 5 * 60 * 1000; STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer(2, &g_current_ms, sizeof(g_current_ms)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); @@ -5093,6 +5213,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_2_message_timeout_succeeds) umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); @@ -5221,7 +5342,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_1_event_item_STRING_type_s IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL); + setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, NULL, NULL, NULL, NULL, NULL, NULL, false, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -5267,7 +5388,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_message_system_properties_ umock_c_reset_all_calls(); setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, - "msg_id", "core_id", TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING, TEST_DIAG_ID, TEST_DIAG_CREATION_TIME_UTC, false, TEST_OUTPUT_NAME); + "msg_id", "core_id", TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING, TEST_DIAG_ID, TEST_DIAG_CREATION_TIME_UTC, false, TEST_OUTPUT_NAME, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -5310,7 +5431,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_message_system_properties_ umock_c_reset_all_calls(); setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, - "msg_id", "core_id", TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING, TEST_DIAG_ID, TEST_DIAG_CREATION_TIME_UTC, true, NULL); + "msg_id", "core_id", TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING, TEST_DIAG_ID, TEST_DIAG_CREATION_TIME_UTC, true, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -5352,7 +5473,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_with_message_incomplete_diagnos umock_c_reset_all_calls(); setup_IoTHubTransport_MQTT_Common_DoWork_events_mocks(NULL, NULL, 0, TEST_IOTHUB_MSG_STRING, false, - NULL, NULL, NULL, NULL, TEST_DIAG_ID, NULL, false, NULL); + NULL, NULL, NULL, NULL, TEST_DIAG_ID, NULL, false, NULL, false); // act IoTHubTransport_MQTT_Common_DoWork(handle); @@ -5403,6 +5524,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_resend_max_recount_reached_mess umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mqtt_client_dowork(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -5483,6 +5605,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_DoWork_mqtt_client_connect_times_out) umock_c_reset_all_calls(); STRICT_EXPECTED_CALL(tickcounter_get_current_ms(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_Credential_Type(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(IoTHubClient_Auth_Get_SasToken_Expiry(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(xio_retrieveoptions(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(mqtt_client_disconnect(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -5852,7 +5975,7 @@ TEST_FUNCTION(IoTHubTransportMqtt_MqttOpCompleteCallback_CONN_ACK_CONN_REFUSED_N TEST_FUNCTION(IoTHubTransport_MQTT_Common_MqttOpCompleteCallback_PUBLISH_ACK_succeed) { // arrange - IOTHUBTRANSPORT_CONFIG config ={ 0 }; + IOTHUBTRANSPORT_CONFIG config = { 0 }; SetupIothubTransportConfig(&config, TEST_DEVICE_ID, TEST_DEVICE_KEY, TEST_IOTHUB_NAME, TEST_IOTHUB_SUFFIX, TEST_PROTOCOL_GATEWAY_HOSTNAME, NULL); PUBLISH_ACK puback; @@ -5869,23 +5992,17 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_MqttOpCompleteCallback_PUBLISH_ACK_suc message1.messageHandle = TEST_IOTHUB_MSG_BYTEARRAY; DList_InsertTailList(config.waitingToSend, &(message1.entry)); - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_SUBSCRIBE_ACK, &suback, g_callbackCtx); IoTHubTransport_MQTT_Common_DoWork(handle); IoTHubTransport_MQTT_Common_DoWork(handle); umock_c_reset_all_calls(); - STRICT_EXPECTED_CALL(DList_RemoveEntryList(IGNORED_PTR_ARG)) - .IgnoreAllArguments(); - STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)) - .IgnoreAllArguments(); - STRICT_EXPECTED_CALL(DList_InsertTailList(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) - .IgnoreAllArguments(); - STRICT_EXPECTED_CALL(Transport_SendComplete_Callback(IGNORED_PTR_ARG, IOTHUB_CLIENT_CONFIRMATION_OK, transport_cb_ctx)) - .IgnoreArgument(1) - .IgnoreArgument(2); - STRICT_EXPECTED_CALL(gballoc_free(NULL)) - .IgnoreArgument(1); + STRICT_EXPECTED_CALL(DList_RemoveEntryList(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(DList_InitializeListHead(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(DList_InsertTailList(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Transport_SendComplete_Callback(IGNORED_PTR_ARG, IOTHUB_CLIENT_CONFIRMATION_OK, transport_cb_ctx)); + STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); // act g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_PUBLISH_ACK, &puback, g_callbackCtx); @@ -7525,7 +7642,7 @@ TEST_FUNCTION(IoTHubTransport_MQTT_Common_ProcessItem_continue_Succeed) suback.qosCount = 1; suback.qosReturn = QosValue; - TRANSPORT_LL_HANDLE handle = IoTHubTransport_MQTT_Common_Create(&config, get_IO_transport, &transport_cb_info, transport_cb_ctx); + TRANSPORT_LL_HANDLE handle = setup_iothub_mqtt_connection(&config); g_fnMqttOperationCallback(TEST_MQTT_CLIENT_HANDLE, MQTT_CLIENT_ON_SUBSCRIBE_ACK, &suback, g_callbackCtx); IoTHubTransport_MQTT_Common_DoWork(handle); diff --git a/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.c b/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.c index 40041fe10a..9b4dbc70ea 100644 --- a/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.c +++ b/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.c @@ -41,7 +41,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/vector.h" #include "azure_c_shared_utility/vector_types_internal.h" #include "azure_c_shared_utility/lock.h" @@ -1273,6 +1273,8 @@ TEST_SUITE_INITIALIZE(suite_init) REGISTER_GLOBAL_MOCK_RETURN(IoTHub_Transport_ValidateCallbacks, 0); REGISTER_GLOBAL_MOCK_FAIL_RETURN(IoTHub_Transport_ValidateCallbacks, __LINE__); + REGISTER_GLOBAL_MOCK_RETURN(IoTHubMessage_IsSecurityMessage, false); + REGISTER_GLOBAL_MOCK_RETURN(HTTPHeaders_FindHeaderValue, TEST_ETAG_VALUE); REGISTER_GLOBAL_MOCK_FAIL_RETURN(HTTPHeaders_FindHeaderValue, NULL); REGISTER_GLOBAL_MOCK_HOOK(HTTPHeaders_GetHeaderCount, my_HTTPHeaders_GetHeaderCount); @@ -1350,6 +1352,34 @@ static void reset_test_data() my_IoTHubClientCore_LL_MessageCallback_messageData = NULL; } +typedef struct MESSAGE_DISPOSITION_CONTEXT_TAG +{ + void* handleData; + void* deviceData; + char* etagValue; +} MESSAGE_DISPOSITION_CONTEXT; + +static MESSAGE_CALLBACK_INFO* make_transport_context_data(IOTHUB_MESSAGE_HANDLE message, void* thd, void* dd) +{ + MESSAGE_CALLBACK_INFO* result = (MESSAGE_CALLBACK_INFO*)malloc(sizeof(MESSAGE_CALLBACK_INFO)); + result->messageHandle = message; + if (thd == NULL && dd == NULL) + { + result->transportContext = NULL; + } + else + { + MESSAGE_DISPOSITION_CONTEXT* tc = (MESSAGE_DISPOSITION_CONTEXT*)malloc(sizeof(MESSAGE_DISPOSITION_CONTEXT)); + tc->handleData = thd; + tc->deviceData = dd; + tc->etagValue = (char*)malloc(20); + sprintf(tc->etagValue, "Hello World"); + result->transportContext = (MESSAGE_DISPOSITION_CONTEXT_HANDLE)tc; + } + + return result; +} + TEST_FUNCTION_INITIALIZE(method_init) { if (TEST_MUTEX_ACQUIRE(g_testByTest)) @@ -3242,34 +3272,6 @@ TEST_FUNCTION(IoTHubTransportHttp_SendMessageDisposition_with_NULL_handle_fails) ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); } -typedef struct MESSAGE_DISPOSITION_CONTEXT_TAG -{ - void* handleData; - void* deviceData; - char* etagValue; -} MESSAGE_DISPOSITION_CONTEXT; - -MESSAGE_CALLBACK_INFO* make_transport_context_data(IOTHUB_MESSAGE_HANDLE message, void* thd, void* dd) -{ - MESSAGE_CALLBACK_INFO* result = (MESSAGE_CALLBACK_INFO*)malloc(sizeof(MESSAGE_CALLBACK_INFO)); - result->messageHandle = message; - if (thd == NULL && dd == NULL) - { - result->transportContext = NULL; - } - else - { - MESSAGE_DISPOSITION_CONTEXT* tc = (MESSAGE_DISPOSITION_CONTEXT*)malloc(sizeof(MESSAGE_DISPOSITION_CONTEXT)); - tc->handleData = thd; - tc->deviceData = dd; - tc->etagValue = (char*)malloc(20); - sprintf(tc->etagValue, "Hello World"); - result->transportContext = (MESSAGE_DISPOSITION_CONTEXT_HANDLE)tc; - } - - return result; -} - //Tests_SRS_TRANSPORTMULTITHTTP_10_002: [If one or both of transportContext fields are NULL, IoTHubTransportHttp_SendMessageDisposition shall fail and return IOTHUB_CLIENT_ERROR.] TEST_FUNCTION(IoTHubTransportHttp_SendMessageDisposition_with_NULL_handle_data_fails) { @@ -7922,7 +7924,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_happy_path_succeeds) .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8045,7 +8047,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_ht .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8168,7 +8170,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_HT .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8292,7 +8294,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_BU .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8400,7 +8402,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_BU .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8496,7 +8498,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_wi .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8571,7 +8573,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_it .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8640,7 +8642,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_it .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8702,7 +8704,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_wi .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -8726,7 +8728,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_wi } //Tests_SRS_TRANSPORTMULTITHTTP_17_067: [ If there is no valid payload, IoTHubTransportHttp_DoWork shall advance to the next activity. ] -TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_Base64_Encode_Bytes_it_fails) +TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_Azure_Base64_Encode_Bytes_it_fails) { //arrange @@ -8758,8 +8760,8 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_Base64_Encode_By .IgnoreArgument(2) .IgnoreArgument(3); - whenShallBase64_Encode_Bytes_fail = 1; - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + whenShallAzure_Base64_Encode_Bytes_fail = 1; + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); /*end of the first batched payload*/ } @@ -8969,7 +8971,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_bigger_than_256K_path .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(bigBufferOverflow, TEST_BIG_BUFFER_1_OVERFLOW_SIZE)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(bigBufferOverflow, TEST_BIG_BUFFER_1_OVERFLOW_SIZE)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9046,7 +9048,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_almost255_happy_path_ .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9174,7 +9176,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_makes_1_batch_succee .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9211,7 +9213,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_makes_1_batch_succee .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer2, buffer2_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer2, buffer2_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9341,7 +9343,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9378,7 +9380,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer2, buffer2_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer2, buffer2_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9499,7 +9501,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9536,7 +9538,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer2, buffer2_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer2, buffer2_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9662,7 +9664,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_the_second_one_does_ .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9699,7 +9701,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_the_second_one_does_ .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9962,12 +9964,12 @@ void setupIrrelevantMocksForProperties(CIoTHubTransportHttpMocks *IOTHUB_MESSAGE if(messageHandle == TEST_IOTHUB_MESSAGE_HANDLE_11) { - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer11, buffer11_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer11, buffer11_size)); } else { - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer6, buffer6_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer6, buffer6_size)); } STRICT_EXPECTED_CALL((*mocks), STRING_delete(IGNORED_PTR_ARG)) @@ -10249,7 +10251,7 @@ void setupIrrelevantMocksForProperties2(CIoTHubTransportHttpMocks *IOTHUB_MESSAG .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer6, buffer6_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer6, buffer6_size)); STRICT_EXPECTED_CALL((*mocks), STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10282,7 +10284,7 @@ void setupIrrelevantMocksForProperties2(CIoTHubTransportHttpMocks *IOTHUB_MESSAG .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer7, buffer7_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer7, buffer7_size)); STRICT_EXPECTED_CALL((*mocks), STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -13836,6 +13838,82 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_SetMessageId_FAILED) } #endif +TEST_FUNCTION(IoTHubTransportHttp_DoWork_SendSecurityMessage_SUCCEED) +{ + //arrange + DList_InsertTailList(&(waitingToSend), &(message6.entry)); + TRANSPORT_LL_HANDLE handle = IoTHubTransportHttp_Create(&TEST_CONFIG, &transport_cb_info, transport_cb_ctx); + (void)IoTHubTransportHttp_Register(handle, &TEST_DEVICE_1, TEST_CONFIG.waitingToSend); + + umock_c_reset_all_calls(); + + setupDoWorkLoopOnceForOneDevice(); + + STRICT_EXPECTED_CALL(DList_IsListEmpty(&waitingToSend)); + + STRICT_EXPECTED_CALL(IoTHubMessage_GetContentType(TEST_IOTHUB_MESSAGE_HANDLE_6)); + STRICT_EXPECTED_CALL(IoTHubMessage_GetByteArray(TEST_IOTHUB_MESSAGE_HANDLE_6, IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .IgnoreArgument(2) + .IgnoreArgument(3); + + STRICT_EXPECTED_CALL(HTTPHeaders_Clone(IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "Content-Type", "application/octet-stream")) + .IgnoreArgument(1); + + /*no properties, so no more headers*/ + STRICT_EXPECTED_CALL(IoTHubMessage_Properties(TEST_IOTHUB_MESSAGE_HANDLE_6)); + STRICT_EXPECTED_CALL(Map_GetInternals(TEST_MAP_1_PROPERTY, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + /*this is making http headers*/ + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-app-" TEST_RED_KEY, TEST_RED_VALUE)); + STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); + + EXPECTED_CALL(IoTHubMessage_GetMessageId(IGNORED_PTR_ARG)).SetReturn(TEST_MESSAGE_ID); + STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-messageid", TEST_MESSAGE_ID)); + EXPECTED_CALL(IoTHubMessage_GetCorrelationId(IGNORED_PTR_ARG)); + EXPECTED_CALL(IoTHubMessage_GetContentTypeSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); + EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); + + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)).SetReturn(true); + + STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-interface-id", "http://security.azureiot.com/SecurityAgent/1.0.0")); + + STRICT_EXPECTED_CALL(BUFFER_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + + /*executing HTTP goodies*/ + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(HTTPAPIEX_SAS_ExecuteRequest( + IGNORED_PTR_ARG, /*sasObject handle */ + IGNORED_PTR_ARG, + HTTPAPI_REQUEST_POST, /*HTTPAPI_REQUEST_TYPE requestType, */ + "/devices/" TEST_DEVICE_ID EVENT_ENDPOINT API_VERSION, /*const char* relativePath, */ + IGNORED_PTR_ARG, /*HTTP_HEADERS_HANDLE requestHttpHeadersHandle, */ + IGNORED_PTR_ARG, /*BUFFER_HANDLE requestContent, */ + IGNORED_PTR_ARG, /*unsigned int* statusCode, */ + NULL, /*HTTP_HEADERS_HANDLE responseHttpHeadersHandle, */ + NULL /*BUFFER_HANDLE responseContent) */ + )) + .IgnoreArgument_requestType() + .CopyOutArgumentBuffer(7, &httpStatus200, sizeof(httpStatus200)); + /*building the list of messages to be notified if HTTP is fine*/ + STRICT_EXPECTED_CALL(DList_RemoveHeadList(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(DList_InsertTailList(IGNORED_PTR_ARG, &(message6.entry))); + STRICT_EXPECTED_CALL(Transport_SendComplete_Callback(IGNORED_PTR_ARG, IOTHUB_CLIENT_CONFIRMATION_OK, IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(BUFFER_delete(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(HTTPHeaders_Free(IGNORED_PTR_ARG)); + + //act + IoTHubTransportHttp_DoWork(handle); + + //assert + ASSERT_ARE_EQUAL(int, 0, memcmp(real_BUFFER_u_char(last_BUFFER_HANDLE_to_HTTPAPIEX_ExecuteRequest), buffer6, buffer6_size)); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + IoTHubTransportHttp_Destroy(handle); +} + // Tests_SRS_TRANSPORTMULTITHTTP_09_003: [ The HTTP header value of `ContentType` shall be set in the `IoTHubMessage_SetContentTypeSystemProperty`] // Tests_SRS_TRANSPORTMULTITHTTP_09_004: [ The HTTP header value of `ContentEncoding` shall be set in the `IoTHub_SetContentEncoding`.] TEST_FUNCTION(IoTHubTransportHttp_DoWork_SetCustomContentType_SetContentEncoding_SUCCEED) @@ -13862,8 +13940,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_SetCustomContentType_SetContentEncoding STRICT_EXPECTED_CALL(BUFFER_new()); - STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)) - .IgnoreArgument(1); /*because relativePath is a STRING_HANDLE*/ + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); /*because relativePath is a STRING_HANDLE*/ STRICT_EXPECTED_CALL(HTTPAPIEX_SAS_ExecuteRequest( IGNORED_PTR_ARG, /*sasObject handle */ IGNORED_PTR_ARG, /*HTTPAPIEX_HANDLE handle, */ @@ -13972,8 +14049,6 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetMessageId_succeeds) STRICT_EXPECTED_CALL(IoTHubMessage_Properties(TEST_IOTHUB_MESSAGE_HANDLE_6)); STRICT_EXPECTED_CALL(Map_GetInternals(TEST_MAP_1_PROPERTY, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); /*this is making http headers*/ - STRICT_EXPECTED_CALL(STRING_construct("iothub-app-")); - STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, TEST_RED_KEY)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-app-" TEST_RED_KEY, TEST_RED_VALUE)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); @@ -13984,8 +14059,10 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetMessageId_succeeds) EXPECTED_CALL(IoTHubMessage_GetContentTypeSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); - STRICT_EXPECTED_CALL(BUFFER_new()); - STRICT_EXPECTED_CALL(BUFFER_build(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(BUFFER_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + /*executing HTTP goodies*/ STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(HTTPAPIEX_SAS_ExecuteRequest( @@ -14041,8 +14118,6 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetCorrelationId_succeeds) STRICT_EXPECTED_CALL(Map_GetInternals(TEST_MAP_1_PROPERTY, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); /*this is making http headers*/ - STRICT_EXPECTED_CALL(STRING_construct("iothub-app-")); - STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, TEST_RED_KEY)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-app-" TEST_RED_KEY, TEST_RED_VALUE)); @@ -14054,8 +14129,9 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetCorrelationId_succeeds) EXPECTED_CALL(IoTHubMessage_GetContentTypeSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); - STRICT_EXPECTED_CALL(BUFFER_new()); - STRICT_EXPECTED_CALL(BUFFER_build(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(BUFFER_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); /*executing HTTP goodies*/ STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)) /*because relativePath*/ @@ -14118,8 +14194,6 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetCustomContentType_succeeds) STRICT_EXPECTED_CALL(Map_GetInternals(TEST_MAP_1_PROPERTY, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); /*this is making http headers*/ - STRICT_EXPECTED_CALL(STRING_construct("iothub-app-")); - STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, TEST_RED_KEY)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-app-" TEST_RED_KEY, TEST_RED_VALUE)); @@ -14131,8 +14205,9 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetCustomContentType_succeeds) STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-contenttype", TEST_CONTENT_TYPE)); EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(IGNORED_PTR_ARG)).SetReturn(NULL); - STRICT_EXPECTED_CALL(BUFFER_new()); - STRICT_EXPECTED_CALL(BUFFER_build(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(BUFFER_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); /*executing HTTP goodies*/ STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)) /*because relativePath*/ @@ -14195,8 +14270,6 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetContentEncoding_succeeds) STRICT_EXPECTED_CALL(Map_GetInternals(TEST_MAP_1_PROPERTY, IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); /*this is making http headers*/ - STRICT_EXPECTED_CALL(STRING_construct("iothub-app-")); - STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, TEST_RED_KEY)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-app-" TEST_RED_KEY, TEST_RED_VALUE)); @@ -14208,12 +14281,12 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_GetContentEncoding_succeeds) EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(IGNORED_PTR_ARG)).SetReturn(TEST_CONTENT_ENCODING); STRICT_EXPECTED_CALL(HTTPHeaders_ReplaceHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-contentencoding", TEST_CONTENT_ENCODING)); - STRICT_EXPECTED_CALL(BUFFER_new()); - STRICT_EXPECTED_CALL(BUFFER_build(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(IGNORED_PTR_ARG)); + + STRICT_EXPECTED_CALL(BUFFER_create(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); /*executing HTTP goodies*/ - STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)) /*because relativePath*/ - .IgnoreArgument(1); + STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); /*because relativePath*/ STRICT_EXPECTED_CALL(HTTPAPIEX_SAS_ExecuteRequest( IGNORED_PTR_ARG, /*sasObject handle */ IGNORED_PTR_ARG, @@ -14365,7 +14438,7 @@ TEST_FUNCTION(IoTHubTransportHttp_GetTwinAsync_returns) { //arrange TRANSPORT_LL_HANDLE handle = IoTHubTransportHttp_Create(&TEST_CONFIG, &transport_cb_info, transport_cb_ctx); - + umock_c_reset_all_calls(); //act diff --git a/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.cpp b/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.cpp index 41e59c105e..403e06e82d 100644 --- a/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.cpp +++ b/iothub_client/tests/iothubtransporthttp_ut/iothubtransporthttp_ut.cpp @@ -9,7 +9,7 @@ #include "macro_utils.h" #undef DEFINE_ENUM -#define DEFINE_ENUM(enumName, ...) typedef enum C2(enumName, _TAG) { FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT, __VA_ARGS__)} enumName; +#define DEFINE_ENUM(enumName, ...) typedef enum C2(enumName, _TAG) { FOR_EACH_1(DEFINE_ENUMERATION_CONSTANT, __VA_ARGS__)} enumName; #include "iothubtransporthttp.h" #include "iothub_client_options.h" @@ -24,7 +24,7 @@ #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/vector.h" #include "azure_c_shared_utility/vector_types_internal.h" #include "azure_c_shared_utility/lock.h" @@ -434,8 +434,8 @@ static size_t whenShallBUFFER_new_fail; static size_t currentBUFFER_build_call; static size_t whenShallBUFFER_build_fail; -static size_t currentBase64_Encode_Bytes_call; -static size_t whenShallBase64_Encode_Bytes_fail; +static size_t currentAzure_Base64_Encode_Bytes_call; +static size_t whenShallAzure_Base64_Encode_Bytes_fail; static size_t currentURL_Encode_String_call; static size_t whenShallURL_Encode_String_fail; @@ -1032,9 +1032,9 @@ TYPED_MOCK_CLASS(CIoTHubTransportHttpMocks, CGlobalMock) MOCK_STATIC_METHOD_2(, int, BUFFER_size, BUFFER_HANDLE, handle, size_t*, size); MOCK_METHOD_END(int, BASEIMPLEMENTATION::BUFFER_size(handle, size)) - MOCK_STATIC_METHOD_2(, STRING_HANDLE, Base64_Encode_Bytes, const unsigned char*, source, size_t, size); - currentBase64_Encode_Bytes_call++; - MOCK_METHOD_END(STRING_HANDLE, (((currentBase64_Encode_Bytes_call > 0) && (currentBase64_Encode_Bytes_call == whenShallBase64_Encode_Bytes_fail)) ? ((STRING_HANDLE)NULL) : BASEIMPLEMENTATION::Base64_Encode_Bytes(source, size))); + MOCK_STATIC_METHOD_2(, STRING_HANDLE, Azure_Base64_Encode_Bytes, const unsigned char*, source, size_t, size); + currentAzure_Base64_Encode_Bytes_call++; + MOCK_METHOD_END(STRING_HANDLE, (((currentAzure_Base64_Encode_Bytes_call > 0) && (currentAzure_Base64_Encode_Bytes_call == whenShallAzure_Base64_Encode_Bytes_fail)) ? ((STRING_HANDLE)NULL) : BASEIMPLEMENTATION::Azure_Base64_Encode_Bytes(source, size))); MOCK_STATIC_METHOD_4(, MAP_RESULT, Map_GetInternals, MAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count) if(handle == TEST_MAP_EMPTY) @@ -1298,7 +1298,7 @@ DECLARE_GLOBAL_MOCK_METHOD_2(CIoTHubTransportHttpMocks, , int, BUFFER_content, B DECLARE_GLOBAL_MOCK_METHOD_2(CIoTHubTransportHttpMocks, , int, BUFFER_size, BUFFER_HANDLE, handle, size_t*, size); //STRING -DECLARE_GLOBAL_MOCK_METHOD_2(CIoTHubTransportHttpMocks, , STRING_HANDLE, Base64_Encode_Bytes, const unsigned char*, source, size_t, size); +DECLARE_GLOBAL_MOCK_METHOD_2(CIoTHubTransportHttpMocks, , STRING_HANDLE, Azure_Base64_Encode_Bytes, const unsigned char*, source, size_t, size); DECLARE_GLOBAL_MOCK_METHOD_1(CIoTHubTransportHttpMocks, , STRING_HANDLE, URL_EncodeString, const char*, textEncode); @@ -1526,7 +1526,7 @@ static void setupRegisterHappyPatheventHTTPrequestHeaders(CIoTHubTransportHttpMo .IgnoreArgument(1); STRICT_EXPECTED_CALL(mocks, HTTPHeaders_AddHeaderNameValuePair(IGNORED_PTR_ARG, "iothub-to", "/devices/" TEST_DEVICE_ID EVENT_ENDPOINT)) .IgnoreArgument(1); - + if(is_x509_used==false) { STRICT_EXPECTED_CALL(mocks, HTTPHeaders_AddHeaderNameValuePair(IGNORED_PTR_ARG, "Authorization", TEST_BLANK_SAS_TOKEN)) @@ -1881,8 +1881,8 @@ TEST_FUNCTION_INITIALIZE(TestMethodInitialize) currentBUFFER_build_call = 0; whenShallBUFFER_build_fail = 0; - currentBase64_Encode_Bytes_call = 0; - whenShallBase64_Encode_Bytes_fail = 0; + currentAzure_Base64_Encode_Bytes_call = 0; + whenShallAzure_Base64_Encode_Bytes_fail = 0; HTTPHeaders_GetHeaderCount_writes_to_its_outputs = true; @@ -1962,7 +1962,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Create_with_NULL_parameter_fails) } -//Tests_SRS_TRANSPORTMULTITHTTP_17_002: [ If field transportConfig is NULL, then IoTHubTransportHttp_Create shall return NULL. +//Tests_SRS_TRANSPORTMULTITHTTP_17_002: [ If field transportConfig is NULL, then IoTHubTransportHttp_Create shall return NULL. TEST_FUNCTION(IoTHubTransportHttp_Create_with_NULL_config_parameter_fails) { // arrange @@ -2010,7 +2010,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Create_with_NULL_iothub_suffix_fails) ASSERT_IS_NULL(result); } -//Tests_SRS_TRANSPORTMULTITHTTP_17_005: [If config->upperConfig->protocolGatewayHostName is NULL, `IoTHubTransportHttp_Create` shall create an immutable string (further called hostname) containing `config->transportConfig->iotHubName + config->transportConfig->iotHubSuffix`.] +//Tests_SRS_TRANSPORTMULTITHTTP_17_005: [If config->upperConfig->protocolGatewayHostName is NULL, `IoTHubTransportHttp_Create` shall create an immutable string (further called hostname) containing `config->transportConfig->iotHubName + config->transportConfig->iotHubSuffix`.] //Tests_SRS_TRANSPORTMULTITHTTP_17_007: [ IoTHubTransportHttp_Create shall create a HTTPAPIEX_HANDLE by a call to HTTPAPIEX_Create passing for hostName the hostname so far constructed by IoTHubTransportHttp_Create. ] //Tests_SRS_TRANSPORTMULTITHTTP_17_009: [ IoTHubTransportHttp_Create shall call VECTOR_create to create a list of registered devices. ] //Tests_SRS_TRANSPORTMULTITHTTP_17_130: [ IoTHubTransportHttp_Create shall allocate memory for the handle. ] @@ -2033,7 +2033,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Create_happy_path) IoTHubTransportHttp_Destroy(result); } -//Tests_SRS_TRANSPORTMULTITHTTP_20_001: [If config->upperConfig->protocolGatewayHostName is not NULL, IoTHubTransportHttp_Create shall use it as hostname] +//Tests_SRS_TRANSPORTMULTITHTTP_20_001: [If config->upperConfig->protocolGatewayHostName is not NULL, IoTHubTransportHttp_Create shall use it as hostname] //Tests_SRS_TRANSPORTMULTITHTTP_17_007: [ IoTHubTransportHttp_Create shall create a HTTPAPIEX_HANDLE by a call to HTTPAPIEX_Create passing for hostName the hostname so far constructed by IoTHubTransportHttp_Create. ] //Tests_SRS_TRANSPORTMULTITHTTP_17_009: [ IoTHubTransportHttp_Create shall call VECTOR_create to create a list of registered devices. ] //Tests_SRS_TRANSPORTMULTITHTTP_17_130: [ IoTHubTransportHttp_Create shall allocate memory for the handle. ] @@ -2379,7 +2379,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_2nd_device_HappyPath_success_fun_time // actual register setupRegisterHappyPath(mocks, false); - ///act + ///act auto devHandle1 = IoTHubTransportHttp_Register(handle, &TEST_DEVICE_1, TEST_IOTHUB_CLIENT_LL_HANDLE, TEST_CONFIG.waitingToSend); @@ -2415,7 +2415,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_sameDevice_twice_returns_null) STRICT_EXPECTED_CALL(mocks, VECTOR_find_if(IGNORED_PTR_ARG, IGNORED_PTR_ARG, TEST_DEVICE_ID)) .IgnoreAllArguments(); - ///act + ///act auto devHandle1b = IoTHubTransportHttp_Register(handle, &TEST_DEVICE_1, TEST_IOTHUB_CLIENT_LL_HANDLE, TEST_CONFIG.waitingToSend); @@ -2495,7 +2495,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_createSASObject_fails_1) } //Tests_SRS_TRANSPORTMULTITHTTP_17_037: [ If the HTTPAPIEX_SAS_Create fails then IoTHubTransportHttp_Register shall fail and return NULL. ] -//Tests_SRS_TRANSPORTMULTITHTTP_17_029: [ If the clone fails then IoTHubTransportHttp_Register shall fail and return NULL. ] +//Tests_SRS_TRANSPORTMULTITHTTP_17_029: [ If the clone fails then IoTHubTransportHttp_Register shall fail and return NULL. ] TEST_FUNCTION(IoTHubTransportHttp_Register_createSASObject_fails_2) { ///arrange @@ -2619,7 +2619,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_createSASObject_fails_4) } //Tests_SRS_TRANSPORTMULTITHTTP_17_037: [ If the HTTPAPIEX_SAS_Create fails then IoTHubTransportHttp_Register shall fail and return NULL. ] -//Tests_SRS_TRANSPORTMULTITHTTP_17_034: [ If the STRING_construct fails then IoTHubTransportHttp_Register shall fail and return NULL. ] +//Tests_SRS_TRANSPORTMULTITHTTP_17_034: [ If the STRING_construct fails then IoTHubTransportHttp_Register shall fail and return NULL. ] TEST_FUNCTION(IoTHubTransportHttp_Register_createSASObject_fails_5) { ///arrange @@ -2880,7 +2880,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_abandonHTTPrelativePathBegin_fails_3) } //Tests_SRS_TRANSPORTMULTITHTTP_17_025: [ If creating the abandonHTTPrelativePathBegin fails then IoTHubTransportHttp_Register shall fail and return NULL. ] -//Tests_SRS_TRANSPORTMULTITHTTP_17_027: [ If the encode fails then IoTHubTransportHttp_Register shall fail and return NULL. ] +//Tests_SRS_TRANSPORTMULTITHTTP_17_027: [ If the encode fails then IoTHubTransportHttp_Register shall fail and return NULL. ] TEST_FUNCTION(IoTHubTransportHttp_Register_abandonHTTPrelativePathBegin_fails_4) { ///arrange @@ -2932,7 +2932,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_messageHTTPrequestheaders_fails_1) setupRegisterHappyPatheventHTTPrelativePath(mocks, deallocateCreated); setupRegisterHappyPathmessageHTTPrelativePath(mocks, deallocateCreated); setupRegisterHappyPatheventHTTPrequestHeaders(mocks, deallocateCreated); - + /*creating message HTTP request headers*/ STRICT_EXPECTED_CALL(mocks, HTTPHeaders_Alloc()); STRICT_EXPECTED_CALL(mocks, IoTHubClient_LL_GetOption(IGNORED_PTR_ARG, OPTION_PRODUCT_INFO, IGNORED_PTR_ARG)) @@ -2975,7 +2975,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Register_messageHTTPrequestheaders_fails_2) setupRegisterHappyPatheventHTTPrelativePath(mocks, deallocateCreated); setupRegisterHappyPathmessageHTTPrelativePath(mocks, deallocateCreated); setupRegisterHappyPatheventHTTPrequestHeaders(mocks, deallocateCreated); - + /*creating message HTTP request headers*/ whenShallHTTPHeaders_Alloc_fail = 2; STRICT_EXPECTED_CALL(mocks, HTTPHeaders_Alloc()); @@ -4111,7 +4111,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Subscribe_with_NULL_parameter_fails) //Tests_SRS_TRANSPORTMULTITHTTP_17_104: [ IoTHubTransportHttp_Subscribe shall locate deviceHandle in the transport device list by calling VECTOR_find_if. ] -//Tests_SRS_TRANSPORTMULTITHTTP_17_106: [ Otherwise, IoTHubTransportHttp_Subscribe shall set the device so that subsequent calls to DoWork should execute HTTP requests. +//Tests_SRS_TRANSPORTMULTITHTTP_17_106: [ Otherwise, IoTHubTransportHttp_Subscribe shall set the device so that subsequent calls to DoWork should execute HTTP requests. TEST_FUNCTION(IoTHubTransportHttp_Subscribe_with_non_NULL_parameter_succeeds) { ///arrange @@ -4137,7 +4137,7 @@ TEST_FUNCTION(IoTHubTransportHttp_Subscribe_with_non_NULL_parameter_succeeds) } //Tests_SRS_TRANSPORTMULTITHTTP_17_104: [ IoTHubTransportHttp_Subscribe shall locate deviceHandle in the transport device list by calling VECTOR_find_if. ] -//Tests_SRS_TRANSPORTMULTITHTTP_17_106: [ Otherwise, IoTHubTransportHttp_Subscribe shall set the device so that subsequent calls to DoWork should execute HTTP requests. +//Tests_SRS_TRANSPORTMULTITHTTP_17_106: [ Otherwise, IoTHubTransportHttp_Subscribe shall set the device so that subsequent calls to DoWork should execute HTTP requests. TEST_FUNCTION(IoTHubTransportHttp_Subscribe_2devices_succeeds) { ///arrange @@ -9378,7 +9378,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_happy_path_succeeds) .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9505,7 +9505,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_ht .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9631,7 +9631,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_HT .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9758,7 +9758,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_BU .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9866,7 +9866,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_items_puts_it_back_when_BU .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -9962,7 +9962,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_wi .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10037,7 +10037,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_it .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10106,7 +10106,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_it .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10168,7 +10168,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_wi .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10192,7 +10192,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_STRING_concat_wi } //Tests_SRS_TRANSPORTMULTITHTTP_17_067: [ If there is no valid payload, IoTHubTransportHttp_DoWork shall advance to the next activity. ] -TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_Base64_Encode_Bytes_it_fails) +TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_Azure_Base64_Encode_Bytes_it_fails) { ///arrange CIoTHubTransportHttpMocks mocks; @@ -10224,8 +10224,8 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_when_Base64_Encode_By .IgnoreArgument(2) .IgnoreArgument(3); - whenShallBase64_Encode_Bytes_fail = 1; - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + whenShallAzure_Base64_Encode_Bytes_fail = 1; + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); /*end of the first batched payload*/ } @@ -10435,7 +10435,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_bigger_than_256K_path .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(bigBufferOverflow, TEST_BIG_BUFFER_1_OVERFLOW_SIZE)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(bigBufferOverflow, TEST_BIG_BUFFER_1_OVERFLOW_SIZE)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10513,7 +10513,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_1_event_item_almost255_happy_path_ .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10645,7 +10645,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_makes_1_batch_succee .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10682,7 +10682,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_makes_1_batch_succee .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer2, buffer2_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer2, buffer2_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10815,7 +10815,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10852,7 +10852,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer2, buffer2_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer2, buffer2_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -10976,7 +10976,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -11013,7 +11013,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_when_the_second_item .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer2, buffer2_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer2, buffer2_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -11143,7 +11143,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_the_second_one_does_ .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(buffer1, buffer1_size)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(buffer1, buffer1_size)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -11180,7 +11180,7 @@ TEST_FUNCTION(IoTHubTransportHttp_DoWork_with_2_event_items_the_second_one_does_ .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL(mocks, Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); + STRICT_EXPECTED_CALL(mocks, Azure_Base64_Encode_Bytes(bigBufferFit, TEST_BIG_BUFFER_1_FIT_SIZE)); STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -11447,12 +11447,12 @@ void setupIrrelevantMocksForProperties(CIoTHubTransportHttpMocks *mocks, IOTHUB_ if(messageHandle == TEST_IOTHUB_MESSAGE_HANDLE_11) { - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer11, buffer11_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer11, buffer11_size)); } else { - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer6, buffer6_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer6, buffer6_size)); } STRICT_EXPECTED_CALL((*mocks), STRING_delete(IGNORED_PTR_ARG)) @@ -11737,7 +11737,7 @@ void setupIrrelevantMocksForProperties2(CIoTHubTransportHttpMocks *mocks, IOTHUB .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer6, buffer6_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer6, buffer6_size)); STRICT_EXPECTED_CALL((*mocks), STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); @@ -11770,7 +11770,7 @@ void setupIrrelevantMocksForProperties2(CIoTHubTransportHttpMocks *mocks, IOTHUB .IgnoreArgument(2) .IgnoreArgument(3); - STRICT_EXPECTED_CALL((*mocks), Base64_Encode_Bytes(buffer7, buffer7_size)); + STRICT_EXPECTED_CALL((*mocks), Azure_Base64_Encode_Bytes(buffer7, buffer7_size)); STRICT_EXPECTED_CALL((*mocks), STRING_delete(IGNORED_PTR_ARG)) .IgnoreArgument(1); diff --git a/iothub_client/tests/uamqp_messaging_ut/uamqp_messaging_ut.c b/iothub_client/tests/uamqp_messaging_ut/uamqp_messaging_ut.c index a5888c43b9..d9fff21d0e 100644 --- a/iothub_client/tests/uamqp_messaging_ut/uamqp_messaging_ut.c +++ b/iothub_client/tests/uamqp_messaging_ut/uamqp_messaging_ut.c @@ -28,6 +28,7 @@ void real_free(void* ptr) #include "umock_c_negative_tests.h" #include "umocktypes.h" #include "umocktypes_c.h" +#include "umocktypes_bool.h" static int saved_malloc_returns_count = 0; static void* saved_malloc_returns[20]; @@ -167,53 +168,81 @@ static int test_amqpvalue_get_uuid(AMQP_VALUE value, uuid* uuid_value) return test_amqpvalue_get_uuid_return; } -static void set_exp_calls_for_create_encoded_annotations_properties(bool has_diagnostic_properties) +static void set_add_map_item(void) { + STRICT_EXPECTED_CALL(amqpvalue_create_symbol(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_create_string(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(amqpvalue_set_map_value(TEST_AMQP_VALUE, TEST_AMQP_VALUE, TEST_AMQP_VALUE)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); +} + +static bool set_exp_calls_for_create_encoded_annotations_properties(bool has_diagnostic_properties, bool has_distributed_tracing_property, bool has_security_props) +{ + bool has_annotations; + size_t encoding_size = TEST_AMQP_ENCODING_SIZE; if (has_diagnostic_properties) { - STRICT_EXPECTED_CALL(IoTHubMessage_GetDiagnosticPropertyData(TEST_IOTHUB_MESSAGE_HANDLE)); + STRICT_EXPECTED_CALL(IoTHubMessage_GetDiagnosticPropertyData(TEST_IOTHUB_MESSAGE_HANDLE)).CallCannotFail(); STRICT_EXPECTED_CALL(amqpvalue_create_map()); - STRICT_EXPECTED_CALL(amqpvalue_create_symbol(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_create_string(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_set_map_value(TEST_AMQP_VALUE, TEST_AMQP_VALUE, TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + set_add_map_item(); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_create_symbol(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_create_string(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_set_map_value(TEST_AMQP_VALUE, TEST_AMQP_VALUE, TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + // Add Map Item + set_add_map_item(); + + STRICT_EXPECTED_CALL(gballoc_free(IGNORED_PTR_ARG)); + } + else + { + STRICT_EXPECTED_CALL(IoTHubMessage_GetDiagnosticPropertyData(TEST_IOTHUB_MESSAGE_HANDLE)).SetReturn(NULL); + } + + if (has_distributed_tracing_property) + { + STRICT_EXPECTED_CALL(IoTHubMessage_GetDistributedTracingSystemProperty(IGNORED_PTR_ARG)) + .CallCannotFail() + .SetReturn(DISTRIBUTED_TRACING_TEST_TRACESTATE); + + if (!has_diagnostic_properties) + { + STRICT_EXPECTED_CALL(amqpvalue_create_map()); + } + set_add_map_item(); + } + else + { + STRICT_EXPECTED_CALL(IoTHubMessage_GetDistributedTracingSystemProperty(IGNORED_PTR_ARG)) + .CallCannotFail() + .SetReturn(NULL); + } + + STRICT_EXPECTED_CALL(IoTHubMessage_IsSecurityMessage(TEST_IOTHUB_MESSAGE_HANDLE)).CallCannotFail().SetReturn(has_security_props); + if (has_security_props) + { + set_add_map_item(); + } + + if (has_diagnostic_properties || has_distributed_tracing_property || has_security_props) + { STRICT_EXPECTED_CALL(amqpvalue_create_message_annotations(TEST_AMQP_VALUE)); STRICT_EXPECTED_CALL(amqpvalue_get_encoded_size(TEST_AMQP_VALUE, IGNORED_PTR_ARG)) .CopyOutArgumentBuffer(2, &encoding_size, sizeof(encoding_size)); - STRICT_EXPECTED_CALL(free(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + + has_annotations = true; } else { - STRICT_EXPECTED_CALL(IoTHubMessage_GetDiagnosticPropertyData(TEST_IOTHUB_MESSAGE_HANDLE)).SetReturn(NULL); + has_annotations = false; } - STRICT_EXPECTED_CALL(IoTHubMessage_GetDistributedTracingSystemProperty(IGNORED_PTR_ARG)).SetReturn(DISTRIBUTED_TRACING_TEST_TRACESTATE); - STRICT_EXPECTED_CALL(amqpvalue_create_map()); - - STRICT_EXPECTED_CALL(amqpvalue_create_symbol(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_create_string(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(amqpvalue_set_map_value(TEST_AMQP_VALUE, TEST_AMQP_VALUE, TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); - - STRICT_EXPECTED_CALL(amqpvalue_create_message_annotations(TEST_AMQP_VALUE)); - STRICT_EXPECTED_CALL(amqpvalue_get_encoded_size(TEST_AMQP_VALUE, IGNORED_PTR_ARG)) - .CopyOutArgumentBuffer(2, &encoding_size, sizeof(encoding_size)); - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + return has_annotations; } static void set_exp_calls_for_create_encoded_message_properties(bool has_message_id, bool has_correlation_id, const char* content_type, const char* content_encoding) @@ -224,7 +253,7 @@ static void set_exp_calls_for_create_encoded_message_properties(bool has_message if (has_message_id) { - STRICT_EXPECTED_CALL(IoTHubMessage_GetMessageId(TEST_IOTHUB_MESSAGE_HANDLE)); + STRICT_EXPECTED_CALL(IoTHubMessage_GetMessageId(TEST_IOTHUB_MESSAGE_HANDLE)).CallCannotFail(); STRICT_EXPECTED_CALL(amqpvalue_create_string(TEST_STRING)); STRICT_EXPECTED_CALL(properties_set_message_id(TEST_PROPERTIES_HANDLE, TEST_AMQP_VALUE)); STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); @@ -236,7 +265,7 @@ static void set_exp_calls_for_create_encoded_message_properties(bool has_message if (has_correlation_id) { - STRICT_EXPECTED_CALL(IoTHubMessage_GetCorrelationId(TEST_IOTHUB_MESSAGE_HANDLE)); + STRICT_EXPECTED_CALL(IoTHubMessage_GetCorrelationId(TEST_IOTHUB_MESSAGE_HANDLE)).CallCannotFail(); STRICT_EXPECTED_CALL(amqpvalue_create_string(TEST_CORRELATION_ID)); STRICT_EXPECTED_CALL(properties_set_correlation_id(TEST_PROPERTIES_HANDLE, TEST_AMQP_VALUE)); STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); @@ -246,7 +275,7 @@ static void set_exp_calls_for_create_encoded_message_properties(bool has_message STRICT_EXPECTED_CALL(IoTHubMessage_GetCorrelationId(TEST_IOTHUB_MESSAGE_HANDLE)).SetReturn(NULL); } - STRICT_EXPECTED_CALL(IoTHubMessage_GetContentTypeSystemProperty(TEST_IOTHUB_MESSAGE_HANDLE)) + STRICT_EXPECTED_CALL(IoTHubMessage_GetContentTypeSystemProperty(TEST_IOTHUB_MESSAGE_HANDLE)).CallCannotFail() .SetReturn(content_type); if (content_type != NULL) @@ -254,7 +283,7 @@ static void set_exp_calls_for_create_encoded_message_properties(bool has_message STRICT_EXPECTED_CALL(properties_set_content_type(IGNORED_PTR_ARG, content_type)); } - STRICT_EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(TEST_IOTHUB_MESSAGE_HANDLE)) + STRICT_EXPECTED_CALL(IoTHubMessage_GetContentEncodingSystemProperty(TEST_IOTHUB_MESSAGE_HANDLE)).CallCannotFail() .SetReturn(content_encoding); if (content_encoding != NULL) @@ -320,11 +349,15 @@ static void set_exp_calls_for_create_encoded_data(IOTHUBMESSAGE_CONTENT_TYPE msg .CopyOutArgumentBuffer(2, &encoding_size, sizeof(encoding_size)); } -static void set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(size_t number_of_app_properties, IOTHUBMESSAGE_CONTENT_TYPE msg_content_type, bool has_message_id, bool has_correlation_id, bool has_diag_properties, const char* content_type, const char* content_encoding) +static void set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message( + size_t number_of_app_properties, IOTHUBMESSAGE_CONTENT_TYPE msg_content_type, bool has_message_id, bool has_correlation_id, + bool has_diag_properties, bool has_distributed_tracing_property, bool has_security_props, const char* content_type, const char* content_encoding) { + bool has_annotations; + set_exp_calls_for_create_encoded_message_properties(has_message_id, has_correlation_id, content_type, content_encoding); set_exp_calls_for_create_encoded_application_properties(number_of_app_properties); - set_exp_calls_for_create_encoded_annotations_properties(has_diag_properties); + has_annotations = set_exp_calls_for_create_encoded_annotations_properties(has_diag_properties, has_distributed_tracing_property, has_security_props); set_exp_calls_for_create_encoded_data(msg_content_type); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)) @@ -336,7 +369,10 @@ static void set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message( STRICT_EXPECTED_CALL(amqpvalue_encode(TEST_AMQP_VALUE, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); } - STRICT_EXPECTED_CALL(amqpvalue_encode(TEST_AMQP_VALUE, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + if (has_annotations) + { + STRICT_EXPECTED_CALL(amqpvalue_encode(TEST_AMQP_VALUE, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + } STRICT_EXPECTED_CALL(amqpvalue_encode(TEST_AMQP_VALUE, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); @@ -345,7 +381,12 @@ static void set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message( { STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); } - STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + + if (has_annotations) + { + STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); + } + STRICT_EXPECTED_CALL(amqpvalue_destroy(TEST_AMQP_VALUE)); } @@ -525,6 +566,8 @@ TEST_SUITE_INITIALIZE(TestClassInitialize) ASSERT_ARE_EQUAL(int, 0, result); result = umocktypes_stdint_register_types(); ASSERT_ARE_EQUAL(int, 0, result); + result = umocktypes_bool_register_types(); + ASSERT_ARE_EQUAL(int, 0, result); REGISTER_UMOCK_ALIAS_TYPE(IOTHUB_MESSAGE_HANDLE, void*); REGISTER_UMOCK_ALIAS_TYPE(IOTHUBMESSAGE_CONTENT_TYPE, int); @@ -668,6 +711,8 @@ TEST_SUITE_INITIALIZE(TestClassInitialize) REGISTER_GLOBAL_MOCK_RETURN(IoTHubMessage_SetContentEncodingSystemProperty, IOTHUB_MESSAGE_OK); REGISTER_GLOBAL_MOCK_FAIL_RETURN(IoTHubMessage_SetContentEncodingSystemProperty, IOTHUB_MESSAGE_ERROR); + REGISTER_GLOBAL_MOCK_RETURN(IoTHubMessage_IsSecurityMessage, false); + REGISTER_GLOBAL_MOCK_RETURN(UUID_to_string, TEST_UUID_STRING); REGISTER_GLOBAL_MOCK_FAIL_RETURN(UUID_to_string, NULL); @@ -733,7 +778,27 @@ TEST_FUNCTION(message_create_uamqp_encoding_from_iothub_message_bytearray_succes { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_BYTEARRAY, true, true, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_BYTEARRAY, true, true, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + + BINARY_DATA binary_data; + memset(&binary_data, 0, sizeof(binary_data)); + + // act + int result = message_create_uamqp_encoding_from_iothub_message(NULL, TEST_IOTHUB_MESSAGE_HANDLE, &binary_data); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_ARE_EQUAL(int, result, 0); + + // cleanup +} + +// Tests_SRS_UAMQP_MESSAGING_32_001: [If optional diagnostic properties are present in the iot hub message, encode them into the AMQP message as annotation properties. Errors stop processing on this message.] +TEST_FUNCTION(message_create_uamqp_encoding_from_iothub_message_with_distributed_tracing_success) +{ + // arrange + umock_c_reset_all_calls(); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_BYTEARRAY, true, true, true, true, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -753,7 +818,7 @@ TEST_FUNCTION(message_create_from_iothub_message_zero_app_properties_success) { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(0, IOTHUBMESSAGE_BYTEARRAY, true, true, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(0, IOTHUBMESSAGE_BYTEARRAY, true, true, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -773,7 +838,7 @@ TEST_FUNCTION(message_create_from_iothub_message_string_success) { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, true, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, true, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -793,7 +858,7 @@ TEST_FUNCTION(message_create_from_iothub_message_no_message_id_success) { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, false, true, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, false, true, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -813,7 +878,7 @@ TEST_FUNCTION(message_create_from_iothub_message_no_diagnostic_properties_succes { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, true, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, true, false, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -833,7 +898,7 @@ TEST_FUNCTION(message_create_from_iothub_message_no_correlation_id_success) { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -853,7 +918,26 @@ TEST_FUNCTION(message_create_from_iothub_message_no_content_type_success) { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, NULL, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, false, false, NULL, TEST_CONTENT_ENCODING); + + BINARY_DATA binary_data; + memset(&binary_data, 0, sizeof(binary_data)); + + ///act + int result = message_create_uamqp_encoding_from_iothub_message(NULL, TEST_IOTHUB_MESSAGE_HANDLE, &binary_data); + + // assert + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + ASSERT_ARE_EQUAL(int, result, 0); + + // cleanup +} + +TEST_FUNCTION(message_create_from_iothub_message_security_msg_success) +{ + // arrange + umock_c_reset_all_calls(); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, true, true, NULL, TEST_CONTENT_ENCODING); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -873,7 +957,7 @@ TEST_FUNCTION(message_create_from_iothub_message_no_content_encoding_success) { // arrange umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, TEST_CONTENT_TYPE, NULL); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, false, true, false, false, TEST_CONTENT_TYPE, NULL); BINARY_DATA binary_data; memset(&binary_data, 0, sizeof(binary_data)); @@ -897,7 +981,7 @@ TEST_FUNCTION(message_create_from_iothub_message_BYTEARRAY_return_errors_fails) result = umock_c_negative_tests_init(); ASSERT_ARE_EQUAL(int, 0, result); umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_BYTEARRAY, true, true, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_BYTEARRAY, true, true, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); umock_c_negative_tests_snapshot(); @@ -905,49 +989,10 @@ TEST_FUNCTION(message_create_from_iothub_message_BYTEARRAY_return_errors_fails) for (size_t i = 0; i < umock_c_negative_tests_call_count(); i++) { // arrange - char error_msg[64]; - umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); - if ((i == 1) || // GetMessageId is optional - (i == 5) || // GetCorrelationId is optional - (i == 4) || // amqpvalue_destroy - (i == 8) || // amqpvalue_destroy - (i == 9) || // ContentType is optional - (i == 11) || // GetContentEncodingSystemProperty is optional - (i == 15) || // properties_destroy - (i == 22) || // amqpvalue_destroy - (i == 23) || // amqpvalue_destroy - (i == 26) || // amqpvalue_destroy - (i == 27) || // GetDiagnosticPropertyData is optional - (i == 28) || // amqpvalue_create_map - (i == 29) || // amqp_create_symbol - (i == 30) || // amqpvalue_create_string - (i == 31) || // amqpvalue_set_map_value - (i == 32) || // amqpvalue_destroy - (i == 33) || // amqpvalue_destroy - (i == 34) || // gballoc_malloc - (i == 35) || // amqp_create_symbol - (i == 36) || // amqpvalue_create_string - (i == 37) || // amqpvalue_set_map_value - (i == 38) || // amqpvalue_destroy - (i == 39) || // amqpvalue_destroy - (i == 40) || // amqpvalue_create_message_annotations - (i == 41) || // amqpvalue_get_encoded_size - (i == 42) || // gballoc_free - (i == 43) || // amqpvalue_destroy - (i == 44) || // GetDistributedTracingSystemProperty is optional - (i == 45) || // amqpvalue_create_map - (i == 49) || // amqpvalue_destroy - (i == 50) || // amqpvalue_destroy - (i == 53) || // amqpvalue_destroy - (i == 58) || // gballoc_malloc - (i == 63) || // amqpvalue_destroy - (i == 64) || // amqpvalue_destroy - (i == 65) || // amqpvalue_destroy - (i == 66) // amqpvalue_destroy - ) + if (!umock_c_negative_tests_can_call_fail(i)) { continue; // these lines have functions that do not return anything (void). } @@ -957,8 +1002,7 @@ TEST_FUNCTION(message_create_from_iothub_message_BYTEARRAY_return_errors_fails) result = message_create_uamqp_encoding_from_iothub_message(NULL, TEST_IOTHUB_MESSAGE_HANDLE, &binary_data); - sprintf(error_msg, "On failed call %lu", (unsigned long)i); - ASSERT_ARE_NOT_EQUAL(int, result, 0, error_msg); + ASSERT_ARE_NOT_EQUAL(int, result, 0, "On failed call %lu", (unsigned long)i); } // cleanup @@ -976,7 +1020,7 @@ TEST_FUNCTION(message_create_from_iothub_message_STRING_return_errors_fails) ASSERT_ARE_EQUAL(int, 0, result); umock_c_reset_all_calls(); - set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, true, true, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); + set_exp_calls_for_message_create_uamqp_encoding_from_iothub_message(1, IOTHUBMESSAGE_STRING, true, true, true, false, false, TEST_CONTENT_TYPE, TEST_CONTENT_ENCODING); umock_c_negative_tests_snapshot(); @@ -984,49 +1028,10 @@ TEST_FUNCTION(message_create_from_iothub_message_STRING_return_errors_fails) for (size_t i = 0; i < umock_c_negative_tests_call_count(); i++) { // arrange - char error_msg[64]; - umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(i); - if ((i == 1) || // GetMessageId is optional - (i == 5) || // GetCorrelationId is optional - (i == 4) || // amqpvalue_destroy - (i == 8) || // amqpvalue_destroy - (i == 9) || // ContentType is optional - (i == 11) || // GetContentEncodingSystemProperty is optional - (i == 15) || // properties_destroy - (i == 22) || // amqpvalue_destroy - (i == 23) || // amqpvalue_destroy - (i == 26) || // amqpvalue_destroy - (i == 27) || // GetDiagnosticPropertyData is optional - (i == 28) || // amqpvalue_create_map - (i == 29) || // amqp_create_symbol - (i == 30) || // amqpvalue_create_string - (i == 31) || // amqpvalue_set_map_value - (i == 32) || // amqpvalue_destroy - (i == 33) || // amqpvalue_destroy - (i == 34) || // gballoc_malloc - (i == 35) || // amqp_create_symbol - (i == 36) || // amqpvalue_create_string - (i == 37) || // amqpvalue_set_map_value - (i == 38) || // amqpvalue_destroy - (i == 39) || // amqpvalue_destroy - (i == 40) || // amqpvalue_create_message_annotations - (i == 41) || // amqpvalue_get_encoded_size - (i == 42) || // gballoc_free - (i == 43) || // amqpvalue_destroy - (i == 44) || // GetDistributedTracingSystemProperty is optional - (i == 45) || // amqpvalue_create_map - (i == 49) || // amqpvalue_destroy - (i == 50) || // amqpvalue_destroy - (i == 53) || // amqpvalue_destroy - (i == 58) || // gballoc_malloc - (i == 63) || // amqpvalue_destroy - (i == 64) || // amqpvalue_destroy - (i == 65) || // amqpvalue_destroy - (i == 66) // amqpvalue_destroy - ) + if (!umock_c_negative_tests_can_call_fail(i)) { continue; // these lines have functions that do not return anything (void). } @@ -1037,9 +1042,7 @@ TEST_FUNCTION(message_create_from_iothub_message_STRING_return_errors_fails) result = message_create_uamqp_encoding_from_iothub_message(NULL, TEST_IOTHUB_MESSAGE_HANDLE, &binary_data); // assert - sprintf(error_msg, "On failed call %lu", (unsigned long)i); - - ASSERT_ARE_NOT_EQUAL(int, result, 0, error_msg); + ASSERT_ARE_NOT_EQUAL(int, result, 0, "On failed call %lu", (unsigned long)i); } // cleanup diff --git a/iothub_client/tests/version_ut/version_ut.c b/iothub_client/tests/version_ut/version_ut.c index 46abd09e53..bda816fbeb 100644 --- a/iothub_client/tests/version_ut/version_ut.c +++ b/iothub_client/tests/version_ut/version_ut.c @@ -8,7 +8,7 @@ BEGIN_TEST_SUITE(version_ut) TEST_FUNCTION(the_version_constant_has_the_expected_value) { - ASSERT_ARE_EQUAL(char_ptr, "1.2.12", IOTHUB_SDK_VERSION); + ASSERT_ARE_EQUAL(char_ptr, "1.3.0", IOTHUB_SDK_VERSION); } /*Tests_SRS_IOTHUBCLIENT_05_001: [IoTHubClient_GetVersionString shall return a pointer to a constant string which indicates the version of IoTHubClient API.]*/ diff --git a/iothub_service_client/devdoc/requirement_docs/iothubserviceclient_auth_requirements.md b/iothub_service_client/devdoc/requirement_docs/iothubserviceclient_auth_requirements.md index d3c0005894..93888df701 100644 --- a/iothub_service_client/devdoc/requirement_docs/iothubserviceclient_auth_requirements.md +++ b/iothub_service_client/devdoc/requirement_docs/iothubserviceclient_auth_requirements.md @@ -24,6 +24,7 @@ typedef struct IOTHUB_SERVICE_CLIENT_AUTH_TAG typedef struct IOTHUB_SERVICE_CLIENT_AUTH_TAG* IOTHUB_SERVICE_CLIENT_AUTH_HANDLE; extern IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionString(const char* connectionString); +extern IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromSharedAccessSignature(const char* connectionString); extern void IoTHubServiceClientAuth_Destroy(IOTHUB_SERVICE_CLIENT_AUTH_HANDLE serviceClientHandle); ``` @@ -106,6 +107,85 @@ extern IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConne **SRS_IOTHUBSERVICECLIENT_12_006: [** If the IOTHUB_SERVICE_CLIENT_AUTH has been populated IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return with a IOTHUB_SERVICE_CLIENT_AUTH_HANDLE to it **]** +## IoTHubServiceClient_CreateFromSharedAccessSignature +```c +extern IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionString(const char* connectionString); +``` +**SRS_IOTHUBSERVICECLIENT_12_001: [** IoTHubServiceClientAuth_CreateFromConnectionString shall verify the input parameter and if it is NULL then return NULL **]** + +**SRS_IOTHUBSERVICECLIENT_12_002: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory for a new service client instance. **]** + +**SRS_IOTHUBSERVICECLIENT_12_003: [** If the allocation failed, IoTHubServiceClientAuth_CreateFromConnectionString shall return NULL **]** + +**SRS_IOTHUBSERVICECLIENT_12_009: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create a STRING_HANDLE from the given connection string by calling STRING_construct. **]** + +**SRS_IOTHUBSERVICECLIENT_12_010: [** If the STRING_construct fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_004: [** IoTHubServiceClientAuth_CreateFromConnectionString shall populate hostName, iotHubName, iotHubSuffix, sharedAccessKeyName, sharedAccessKeyValue from the given connection string by calling connectionstringparser_parse **]** + +**SRS_IOTHUBSERVICECLIENT_12_005: [** If populating the IOTHUB_SERVICE_CLIENT_AUTH fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL **]** + +**SRS_IOTHUBSERVICECLIENT_12_011: [** If the populating HostName fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_012: [** If the populating SharedAccessKeyName fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_013: [** If the populating SharedAccessKey fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_038: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create a STRING_handle from hostName by calling STRING_construct. **]** + +**SRS_IOTHUBSERVICECLIENT_12_039: [** If the STRING_construct fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_014: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create a STRING_TOKENIZER to parse HostName by calling STRING_TOKENIZER_create. **]** + +**SRS_IOTHUBSERVICECLIENT_12_015: [** If the STRING_TOKENIZER_create fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_016: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create a new STRING_HANDLE for token key string by calling STRING_new. **]** + +**SRS_IOTHUBSERVICECLIENT_12_017: [** If the STRING_new fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_018: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create a new STRING_HANDLE for token value string by calling STRING_new. **]** + +**SRS_IOTHUBSERVICECLIENT_12_019: [** If the STRING_new fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_020: [** IoTHubServiceClientAuth_CreateFromConnectionString shall call STRING_TOKENIZER_get_next_token to get token key string. **]** + +**SRS_IOTHUBSERVICECLIENT_12_021: [** If the STRING_TOKENIZER_get_next_token fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_022: [** IoTHubServiceClientAuth_CreateFromConnectionString shall call STRING_TOKENIZER_get_next_token to get token value string. **]** + +**SRS_IOTHUBSERVICECLIENT_12_023: [** If the STRING_TOKENIZER_get_next_token fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_034: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create C string from token key string handle by calling STRING_c_str. **]** + +**SRS_IOTHUBSERVICECLIENT_12_035: [** If the STRING_c_str fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_036: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create C string from token value string handle by calling STRING_c_str. **]** + +**SRS_IOTHUBSERVICECLIENT_12_037: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_024: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy hostName to result->hostName by calling mallocAndStrcpy_s. **]** + +**SRS_IOTHUBSERVICECLIENT_12_025: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_026: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy keyName to result->keyName by calling mallocAndStrcpy_s. **]** + +**SRS_IOTHUBSERVICECLIENT_12_027: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_028: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy sharedAccessKey to result->sharedAccessKey by calling mallocAndStrcpy_s. **]** + +**SRS_IOTHUBSERVICECLIENT_12_029: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_030: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy iothubName to result->iothubName by calling mallocAndStrcpy_s. **]** + +**SRS_IOTHUBSERVICECLIENT_12_031: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_032: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy iothubSuffix to result->iothubSuffix by calling mallocAndStrcpy_s. **]** + +**SRS_IOTHUBSERVICECLIENT_12_033: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **]** + +**SRS_IOTHUBSERVICECLIENT_12_006: [** If the IOTHUB_SERVICE_CLIENT_AUTH has been populated IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return with a IOTHUB_SERVICE_CLIENT_AUTH_HANDLE to it **]** + +**SRS_IOTHUBSERVICECLIENT_12_041: [** IoTHubServiceClientAuth_CreateFromSharedAccessSignature shall allocate memory and copy sharedAccessSignature to result->sharedAccessKey by prefixing it with "sas=". **]** ## IoTHubServiceClient_Destroy ```c diff --git a/iothub_service_client/inc/iothub_registrymanager.h b/iothub_service_client/inc/iothub_registrymanager.h index 489c4729e4..8793b0a40d 100644 --- a/iothub_service_client/inc/iothub_registrymanager.h +++ b/iothub_service_client/inc/iothub_registrymanager.h @@ -172,7 +172,7 @@ typedef struct IOTHUB_REGISTRYMANAGER_TAG char* hostname; char* iothubName; char* iothubSuffix; - char* sharedAccessKey; + char* sharedAccessKey; //field can contain "SharedAccessSignature" if prefixed with "sas="; Otherwise, a "SharedAccessKey" is expected. char* keyName; char* deviceId; } IOTHUB_REGISTRYMANAGER; diff --git a/iothub_service_client/inc/iothub_service_client_auth.h b/iothub_service_client/inc/iothub_service_client_auth.h index 2c7ff46de3..b914c4fd91 100644 --- a/iothub_service_client/inc/iothub_service_client_auth.h +++ b/iothub_service_client/inc/iothub_service_client_auth.h @@ -49,7 +49,7 @@ typedef struct IOTHUB_SERVICE_CLIENT_AUTH_TAG char* hostname; char* iothubName; char* iothubSuffix; - char* sharedAccessKey; + char* sharedAccessKey; //field can contain "SharedAccessSignature" if prefixed with "sas="; Otherwise, a "SharedAccessKey" is expected. char* keyName; char* deviceId; } IOTHUB_SERVICE_CLIENT_AUTH; @@ -74,6 +74,22 @@ typedef struct IOTHUB_SERVICE_CLIENT_AUTH_TAG* IOTHUB_SERVICE_CLIENT_AUTH_HANDLE */ extern IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionString(const char* connectionString); +/** +* @brief Creates a IoT Hub service client handle for use it +* in consequent APIs. +* +* @param connectionString Pointer to a character string +* +* Sample connection string: +*
+*
HostName=[IoT Hub name goes here].[IoT Hub suffix goes here, e.g., private.azure-devices-int.net];SharedAccessSignature=[Shared Access Signature goes here];
+*
+* +* @return A non-NULL @c IOTHUB_SERVICE_CLIENT_AUTH_HANDLE value that is used when +* invoking other functions for IoT Hub Service Client and @c NULL on failure. +*/ +extern IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromSharedAccessSignature(const char* connectionString); + /** * @brief Disposes of resources allocated by the IoT Hub Service Client. * diff --git a/iothub_service_client/src/iothub_deviceconfiguration.c b/iothub_service_client/src/iothub_deviceconfiguration.c index 7861d9a5ad..1cb151b9fa 100644 --- a/iothub_service_client/src/iothub_deviceconfiguration.c +++ b/iothub_service_client/src/iothub_deviceconfiguration.c @@ -12,7 +12,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/uniqueid.h" #include "azure_c_shared_utility/connection_string_parser.h" diff --git a/iothub_service_client/src/iothub_devicemethod.c b/iothub_service_client/src/iothub_devicemethod.c index 3b95074168..c74fc5caab 100644 --- a/iothub_service_client/src/iothub_devicemethod.c +++ b/iothub_service_client/src/iothub_devicemethod.c @@ -11,7 +11,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/uniqueid.h" #include "azure_c_shared_utility/connection_string_parser.h" diff --git a/iothub_service_client/src/iothub_devicetwin.c b/iothub_service_client/src/iothub_devicetwin.c index 23d5de202f..c2a1e30f8f 100644 --- a/iothub_service_client/src/iothub_devicetwin.c +++ b/iothub_service_client/src/iothub_devicetwin.c @@ -12,7 +12,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/httpapiex.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/uniqueid.h" #include "azure_c_shared_utility/connection_string_parser.h" diff --git a/iothub_service_client/src/iothub_service_client.def b/iothub_service_client/src/iothub_service_client.def index 8e279aace7..e968d51cdd 100644 --- a/iothub_service_client/src/iothub_service_client.def +++ b/iothub_service_client/src/iothub_service_client.def @@ -20,6 +20,7 @@ EXPORTS IoTHubMessage_Destroy IoTHubServiceClient_GetVersionString IoTHubServiceClientAuth_CreateFromConnectionString + IoTHubServiceClientAuth_CreateFromSharedAccessSignature IoTHubServiceClientAuth_Destroy IoTHubDeviceConfiguration_Create IoTHubDeviceConfiguration_Destroy diff --git a/iothub_service_client/src/iothub_service_client_auth.c b/iothub_service_client/src/iothub_service_client_auth.c index 8eff59bcd5..62a4de5a89 100644 --- a/iothub_service_client/src/iothub_service_client_auth.c +++ b/iothub_service_client/src/iothub_service_client_auth.c @@ -14,7 +14,9 @@ static const char* IOTHUBHOSTNAME = "HostName"; static const char* IOTHUBSHAREDACESSKEYNAME = "SharedAccessKeyName"; static const char* IOTHUBSHAREDACESSKEY = "SharedAccessKey"; +static const char* IOTHUBSHAREDACESSSIGNATURE = "SharedAccessSignature"; static const char* IOTHUBDEVICEID = "DeviceId"; +static const char* IOTHUBSASPREFIX = "sas="; static void free_service_client_auth(IOTHUB_SERVICE_CLIENT_AUTH* authInfo) { @@ -30,7 +32,7 @@ static void free_service_client_auth(IOTHUB_SERVICE_CLIENT_AUTH* authInfo) DEFINE_ENUM_STRINGS(IOTHUB_DEVICE_STATUS, IOTHUB_DEVICE_STATUS_VALUES); DEFINE_ENUM_STRINGS(IOTHUB_DEVICE_CONNECTION_STATE, IOTHUB_DEVICE_CONNECTION_STATE_VALUES); -IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionString(const char* connectionString) +static IOTHUB_SERVICE_CLIENT_AUTH_HANDLE create_from_connection_string(const char* connectionString, bool useSharedAccessSignature) { IOTHUB_SERVICE_CLIENT_AUTH_HANDLE result; @@ -79,10 +81,11 @@ IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionSt STRING_HANDLE token_key_string = NULL; STRING_HANDLE token_value_string = NULL; STRING_HANDLE host_name_string = NULL; + STRING_HANDLE shared_access = NULL; const char* hostName; const char* keyName; const char* deviceId; - const char* sharedAccessKey; + const char* sharedAccess = NULL; const char* iothubName; const char* iothubSuffix; @@ -111,13 +114,20 @@ IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionSt free_service_client_auth(result); result = NULL; } - else if ((sharedAccessKey = Map_GetValueFromKey(connection_string_values_map, IOTHUBSHAREDACESSKEY)) == NULL) + else if (!useSharedAccessSignature && (sharedAccess = Map_GetValueFromKey(connection_string_values_map, IOTHUBSHAREDACESSKEY)) == NULL) { /*Codes_SRS_IOTHUBSERVICECLIENT_12_013: [** If the populating SharedAccessKey fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **] */ LogError("Couldn't find %s in connection string", IOTHUBSHAREDACESSKEY); free_service_client_auth(result); result = NULL; } + else if (useSharedAccessSignature && (sharedAccess = Map_GetValueFromKey(connection_string_values_map, IOTHUBSHAREDACESSSIGNATURE)) == NULL) + { + /*Codes_SRS_IOTHUBSERVICECLIENT_12_013: [** If the populating SharedAccessKey fails, IoTHubServiceClientAuth_CreateFromSharedAccessSignature shall do clean up and return NULL. **] */ + LogError("Couldn't find %s in connection string", IOTHUBSHAREDACESSSIGNATURE); + free_service_client_auth(result); + result = NULL; + } /*Codes_SRS_IOTHUBSERVICECLIENT_12_038: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create a STRING_handle from hostName by calling STRING_construct. **] */ else if ((host_name_string = STRING_construct(hostName)) == NULL) { @@ -191,13 +201,25 @@ IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionSt result = NULL; } /*Codes_SRS_IOTHUBSERVICECLIENT_12_028: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy sharedAccessKey to result->sharedAccessKey by calling mallocAndStrcpy_s. **] */ - else if (mallocAndStrcpy_s(&result->sharedAccessKey, sharedAccessKey) != 0) + else if (!useSharedAccessSignature && (sharedAccess != NULL) && mallocAndStrcpy_s(&result->sharedAccessKey, sharedAccess) != 0) { /*Codes_SRS_IOTHUBSERVICECLIENT_12_029: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **] */ LogError("mallocAndStrcpy_s failed for sharedAccessKey"); free_service_client_auth(result); result = NULL; } + /*Codes_SRS_IOTHUBSERVICECLIENT_12_041: [** IoTHubServiceClientAuth_CreateFromSharedAccessSignature shall allocate memory and copy sharedAccessSignature to result->sharedAccessKey by prefixing it with "sas=". **] */ + else if (useSharedAccessSignature && + (sharedAccess != NULL) && + ((shared_access = STRING_construct(IOTHUBSASPREFIX)) != NULL) && + (STRING_concat(shared_access, sharedAccess) != 0) && + (mallocAndStrcpy_s(&result->sharedAccessKey, STRING_c_str(shared_access)) != 0)) + { + /*Codes_SRS_IOTHUBSERVICECLIENT_12_029: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromSharedAccessSignature shall do clean up and return NULL. **] */ + LogError("mallocAndStrcpy_s failed for sharedAccessSignature"); + free_service_client_auth(result); + result = NULL; + } /*Codes_SRS_IOTHUBSERVICECLIENT_12_034: [** IoTHubServiceClientAuth_CreateFromConnectionString shall create C string from token key string handle by calling STRING_c_str. **] */ else if ((iothubName = STRING_c_str(token_key_string)) == NULL) { @@ -236,6 +258,10 @@ IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionSt STRING_delete(host_name_string); STRING_TOKENIZER_destroy(tokenizer); Map_Destroy(connection_string_values_map); + if (useSharedAccessSignature) + { + STRING_delete(shared_access); + } } STRING_delete(connection_string); } @@ -244,6 +270,16 @@ IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionSt return result; } +IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromConnectionString(const char* connectionString) +{ + return create_from_connection_string(connectionString, false); +} + +IOTHUB_SERVICE_CLIENT_AUTH_HANDLE IoTHubServiceClientAuth_CreateFromSharedAccessSignature(const char* connectionString) +{ + return create_from_connection_string(connectionString, true); +} + void IoTHubServiceClientAuth_Destroy(IOTHUB_SERVICE_CLIENT_AUTH_HANDLE serviceClientHandle) { /*Codes_SRS_IOTHUBSERVICECLIENT_12_007: [** If the serviceClientHandle input parameter is NULL IoTHubServiceClient_Destroy shall return **]*/ diff --git a/iothub_service_client/tests/iothub_srv_client_auth_ut/iothub_service_client_auth_ut.cpp b/iothub_service_client/tests/iothub_srv_client_auth_ut/iothub_service_client_auth_ut.cpp index bd1cbbe258..52c83bd8f5 100644 --- a/iothub_service_client/tests/iothub_srv_client_auth_ut/iothub_service_client_auth_ut.cpp +++ b/iothub_service_client/tests/iothub_srv_client_auth_ut/iothub_service_client_auth_ut.cpp @@ -57,6 +57,8 @@ static STRING_HANDLE TEST_VALUE_STRING_HANDLE = (STRING_HANDLE)0x4646; static const char* TEST_CHAR_PTR = "TestString"; static const char* TEST_CONNECTION_STRING = "HostName=aaa.bbb.net;SharedAccessKeyName=xxx;SharedAccessKey=yyy"; +static const char* TEST_SAS_CONNECTION_STRING = "HostName=aaa.bbb.net;SharedAccessSignature=yyy"; +static const char* TEST_SAS_PREFIX_STRING = "sas="; static size_t currentmalloc_call; static size_t whenShallmalloc_fail; @@ -112,6 +114,8 @@ TYPED_MOCK_CLASS(CIoTHubServiceClientAuthMocks, CGlobalMock) MOCK_METHOD_END(STRING_HANDLE, TEST_STRING_HANDLE); MOCK_STATIC_METHOD_1(, STRING_HANDLE, STRING_construct, const char*, s) MOCK_METHOD_END(STRING_HANDLE, TEST_STRING_HANDLE); + MOCK_STATIC_METHOD_2(, int, STRING_concat, STRING_HANDLE, handle, const char*, s) + MOCK_METHOD_END(int, 1); MOCK_STATIC_METHOD_1(, void, STRING_delete, STRING_HANDLE, handle) MOCK_VOID_METHOD_END(); MOCK_STATIC_METHOD_1(, const char*, STRING_c_str, STRING_HANDLE, s) @@ -144,6 +148,7 @@ DECLARE_GLOBAL_MOCK_METHOD_2(CIoTHubServiceClientAuthMocks, , const char*, Map_G DECLARE_GLOBAL_MOCK_METHOD_0(CIoTHubServiceClientAuthMocks, , STRING_HANDLE, STRING_new); DECLARE_GLOBAL_MOCK_METHOD_1(CIoTHubServiceClientAuthMocks, , STRING_HANDLE, STRING_construct, const char*, s); +DECLARE_GLOBAL_MOCK_METHOD_2(CIoTHubServiceClientAuthMocks, , int, STRING_concat, STRING_HANDLE, handle, const char*, s); DECLARE_GLOBAL_MOCK_METHOD_1(CIoTHubServiceClientAuthMocks, , void, STRING_delete, STRING_HANDLE, handle); DECLARE_GLOBAL_MOCK_METHOD_1(CIoTHubServiceClientAuthMocks, , const char*, STRING_c_str, STRING_HANDLE, s); @@ -892,6 +897,174 @@ TEST_FUNCTION(IoTHubServiceClientAuth_CreateFromConnectionString_do_clean_up_if_ mocks.AssertActualAndExpectedCalls(); } +/* Tests_SRS_IOTHUBSERVICECLIENT_12_041: [** IoTHubServiceClientAuth_CreateFromSharedAccessSignature shall allocate memory and copy sharedAccessSignature to result->sharedAccessKey by prefixing it with "sas=". **] */ +TEST_FUNCTION(IoTHubServiceClientAuth_CreateFromConnectionString_for_sharedAccessSignature) +{ + // arrange + CIoTHubServiceClientAuthMocks mocks; + + whenShallmalloc_fail = 0; + STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG)) + .IgnoreArgument(1); + + STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_SAS_CONNECTION_STRING)); + + STRICT_EXPECTED_CALL(mocks, connectionstringparser_parse(TEST_STRING_HANDLE)) + .SetReturn(TEST_MAP_HANDLE); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"SharedAccessKeyName")) + .SetReturn(TEST_CONST_CHAR_PTR); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"DeviceId")) + .SetReturn(TEST_CONST_CHAR_PTR_NULL); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"HostName")) + .SetReturn(TEST_CONST_CHAR_PTR); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"SharedAccessSignature")) + .SetReturn(TEST_CONST_CHAR_PTR); + + STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONST_CHAR_PTR)); + + STRICT_EXPECTED_CALL(mocks, STRING_TOKENIZER_create(TEST_STRING_HANDLE)) + .SetReturn(TEST_STRING_TOKENIZER_HANDLE); + + STRICT_EXPECTED_CALL(mocks, STRING_new()) + .SetReturn(TEST_STRING_HANDLE); + + STRICT_EXPECTED_CALL(mocks, STRING_new()) + .SetReturn(TEST_STRING_HANDLE); + + STRICT_EXPECTED_CALL(mocks, STRING_TOKENIZER_get_next_token(TEST_STRING_TOKENIZER_HANDLE, TEST_STRING_HANDLE, ".")) + .SetReturn(0); + + STRICT_EXPECTED_CALL(mocks, STRING_TOKENIZER_get_next_token(TEST_STRING_TOKENIZER_HANDLE, TEST_STRING_HANDLE, "0")) + .SetReturn(0); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_SAS_PREFIX_STRING)); + + EXPECTED_CALL(mocks, STRING_concat(TEST_STRING_HANDLE, TEST_CHAR_PTR)); + + EXPECTED_CALL(mocks, STRING_c_str(TEST_STRING_HANDLE)) + .SetReturn(TEST_CHAR_PTR); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + EXPECTED_CALL(mocks, STRING_c_str(TEST_STRING_HANDLE)) + .SetReturn(TEST_CHAR_PTR); + + EXPECTED_CALL(mocks, STRING_c_str(TEST_STRING_HANDLE)) + .SetReturn(TEST_CHAR_PTR); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + set_expected_calls_for_CreateFromConnectionString_cleanup(mocks); + + STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) + .IgnoreAllArguments(); + + + // act + IOTHUB_SERVICE_CLIENT_AUTH_HANDLE result = IoTHubServiceClientAuth_CreateFromSharedAccessSignature(TEST_SAS_CONNECTION_STRING); + + // assert + ASSERT_IS_NOT_NULL(result); + + if (result != NULL) + { + free(result); + } + + mocks.AssertActualAndExpectedCalls(); +} + +/* Tests_SRS_IOTHUBSERVICECLIENT_12_041: [** IoTHubServiceClientAuth_CreateFromSharedAccessSignature shall allocate memory and copy sharedAccessSignature to result->sharedAccessKey by prefixing it with "sas=". **] */ +/* Tests_SRS_IOTHUBSERVICECLIENT_12_029: [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **] */ +TEST_FUNCTION(IoTHubServiceClientAuth_CreateFromConnectionString_do_clean_up_if_mallocAndStrcpy_s_for_sharedAccessSignature_fails) +{ + // arrange + CIoTHubServiceClientAuthMocks mocks; + + whenShallmalloc_fail = 0; + STRICT_EXPECTED_CALL(mocks, gballoc_malloc(IGNORED_NUM_ARG)) + .IgnoreArgument(1); + + STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_SAS_CONNECTION_STRING)); + + STRICT_EXPECTED_CALL(mocks, connectionstringparser_parse(TEST_STRING_HANDLE)) + .SetReturn(TEST_MAP_HANDLE); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"SharedAccessKeyName")) + .SetReturn(TEST_CONST_CHAR_PTR); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"DeviceId")) + .SetReturn(TEST_CONST_CHAR_PTR_NULL); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"HostName")) + .SetReturn(TEST_CONST_CHAR_PTR); + + STRICT_EXPECTED_CALL(mocks, Map_GetValueFromKey(TEST_MAP_HANDLE, (const char*)"SharedAccessSignature")) + .SetReturn(TEST_CONST_CHAR_PTR); + + STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_CONST_CHAR_PTR)); + + STRICT_EXPECTED_CALL(mocks, STRING_TOKENIZER_create(TEST_STRING_HANDLE)) + .SetReturn(TEST_STRING_TOKENIZER_HANDLE); + + STRICT_EXPECTED_CALL(mocks, STRING_new()) + .SetReturn(TEST_STRING_HANDLE); + + STRICT_EXPECTED_CALL(mocks, STRING_new()) + .SetReturn(TEST_STRING_HANDLE); + + STRICT_EXPECTED_CALL(mocks, STRING_TOKENIZER_get_next_token(TEST_STRING_TOKENIZER_HANDLE, TEST_STRING_HANDLE, ".")) + .SetReturn(0); + + STRICT_EXPECTED_CALL(mocks, STRING_TOKENIZER_get_next_token(TEST_STRING_TOKENIZER_HANDLE, TEST_STRING_HANDLE, "0")) + .SetReturn(0); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(0); + + STRICT_EXPECTED_CALL(mocks, STRING_construct(TEST_SAS_PREFIX_STRING)); + + EXPECTED_CALL(mocks, STRING_concat(TEST_STRING_HANDLE, TEST_CHAR_PTR)); + + EXPECTED_CALL(mocks, STRING_c_str(TEST_STRING_HANDLE)) + .SetReturn(TEST_CHAR_PTR); + + EXPECTED_CALL(mocks, mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)) + .SetReturn(1); + + set_expected_calls_for_free_service_client_auth(mocks); + set_expected_calls_for_CreateFromConnectionString_cleanup(mocks); + + STRICT_EXPECTED_CALL(mocks, STRING_delete(IGNORED_PTR_ARG)) + .IgnoreAllArguments(); + + + // act + IOTHUB_SERVICE_CLIENT_AUTH_HANDLE result = IoTHubServiceClientAuth_CreateFromSharedAccessSignature(TEST_SAS_CONNECTION_STRING); + + // assert + ASSERT_ARE_EQUAL(void_ptr, NULL, result); + mocks.AssertActualAndExpectedCalls(); +} + /* Tests_SRS_IOTHUBSERVICECLIENT_12_030: [** IoTHubServiceClientAuth_CreateFromConnectionString shall allocate memory and copy iothubName to result->iothubName by calling mallocAndStrcpy_s. **] */ /* Tests_SRS_IOTHUBSERVICECLIENT_12_031 : [** If the mallocAndStrcpy_s fails, IoTHubServiceClientAuth_CreateFromConnectionString shall do clean up and return NULL. **] */ TEST_FUNCTION(IoTHubServiceClientAuth_CreateFromConnectionString_do_clean_up_if_mallocAndStrcpy_s_for_iothubName_fails) diff --git a/provisioning_client/adapters/hsm_client_http_edge.c b/provisioning_client/adapters/hsm_client_http_edge.c index 61bfb0f9f9..598214862f 100755 --- a/provisioning_client/adapters/hsm_client_http_edge.c +++ b/provisioning_client/adapters/hsm_client_http_edge.c @@ -11,7 +11,7 @@ #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/socketio.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/shared_util_options.h" #include "azure_uhttp_c/uhttp.h" @@ -282,7 +282,7 @@ static BUFFER_HANDLE construct_json_signing_blob(const char* data) LogError("STRING_concat failed"); result = NULL; } - else if ((data_base64_encoded = Base64_Encode_Bytes((const unsigned char*)STRING_c_str(data_url_encoded), strlen(STRING_c_str(data_url_encoded)))) == NULL) + else if ((data_base64_encoded = Azure_Base64_Encode_Bytes((const unsigned char*)STRING_c_str(data_url_encoded), strlen(STRING_c_str(data_url_encoded)))) == NULL) { LogError("base64 encoding of string %s failed", STRING_c_str(data_url_encoded)); result = NULL; diff --git a/provisioning_client/adapters/hsm_client_tpm.c b/provisioning_client/adapters/hsm_client_tpm.c index 5d1543393f..55c1ba8638 100644 --- a/provisioning_client/adapters/hsm_client_tpm.c +++ b/provisioning_client/adapters/hsm_client_tpm.c @@ -7,7 +7,7 @@ #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sastoken.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/strings.h" @@ -418,7 +418,7 @@ static BUFFER_HANDLE decrypt_data(HSM_CLIENT_INFO* sec_info, const unsigned char curr_pos += enc_data_size; act_size -= enc_data_size; - // decrypts encrypted symmetric key �encSecret� and returns it as 'tpm_blob'. + // decrypts encrypted symmetric key encSecret and returns it as 'tpm_blob'. // Later 'tpm_blob' is used as the inner wrapper key for import of the HMAC key blob. if (TPM2_ActivateCredential(&sec_info->tpm_device, &NullPwSession, &ek_sess, TPM_20_SRK_HANDLE, TPM_20_EK_HANDLE, &tpm_blob, &tpm_enc_secret, &inner_wrap_key) != TPM_RC_SUCCESS) { diff --git a/provisioning_client/deps/utpm b/provisioning_client/deps/utpm index 02ab1c39d2..fac5194ee4 160000 --- a/provisioning_client/deps/utpm +++ b/provisioning_client/deps/utpm @@ -1 +1 @@ -Subproject commit 02ab1c39d25a8207f7bc5d21d59accdc96c218d4 +Subproject commit fac5194ee46714689e37c8f277fe2a64d5a8a963 diff --git a/provisioning_client/devdoc/azure_provisioning_faq.md b/provisioning_client/devdoc/azure_provisioning_faq.md new file mode 100644 index 0000000000..91e3510930 --- /dev/null +++ b/provisioning_client/devdoc/azure_provisioning_faq.md @@ -0,0 +1,51 @@ +# Azure IoT Provisioning Client FAQ + +Here is where we answer question pertaining to the IoT Provisioning Client. Please read the following documents for an overview of the [Device Provisioning Service](https://docs.microsoft.com/en-us/azure/iot-dps/) + +## x509 Provisioning + +- How does the provisioning service match the device's X.509 certificate to an enrollment? + + - The Provisioning Client adds the x509 certificate on the TLS stream. The Device Provisioning Service uses this certificate to look up the proper enrollment record. + +- Where does the x509 certificate come from? + + - This question depends on the situation: + + - **Development**: The SDK ships with a development HSM implementation that generates a test x509 certificate with a pre-generated key. This enables the developer to quickly get up and running to test their solutions. + + - **Production**: For production situations, the developer should create a custom HSM library to retrieve the certificate from a hardware backed HSM or a software solution (for more information on this please see [using custom hsm](https://github.com/Azure/azure-iot-sdk-c/blob/master/provisioning_client/devdoc/using_custom_hsm.md)) + + For more information on switching between development and production scenarios, refer to [using provisioning client](https://github.com/Azure/azure-iot-sdk-c/blob/master/provisioning_client/devdoc/using_provisioning_client.md) + + For more reading on certificates information, please see [security concept document](https://docs.microsoft.com/en-us/azure/iot-dps/concepts-security#x509-certificates) + +- What if I want the certificate private key to never leave the hardware? + + - One of the benefits of having an HSM is that it can ensure that the private key will never leave the hardware device, but to get this functionality it will require a little more code. + + - You will need to write a custom HSM to be able to extract the certificate and return the alias private key to the SDK (more on this in a moment) see the [custom hsm sample](https://github.com/Azure/azure-iot-sdk-c/blob/master/provisioning_client/samples/custom_hsm_example/custom_hsm_example.c) in the SDK. + + - You will need to have a TLS engine that can communicate with the target hardware that is connected to the device. You can review your hardware device documentation for information on obtaining a hardware TLS engine. + + - You will also need to create a custom azure iot tlsio library to communicate with the hardware TLS engine. You can use the [tlsio_template](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_template.c) to get started or you can look at an already complete tlsio such as [tlsio_openssl](https://github.com/Azure/azure-c-shared-utility/blob/master/adapters/tlsio_openssl.c) + + - More on Alias Private Keys + + - The custom HSM uses the concept of **Alias Private Keys** to deal with keeping the private keys information in the hardware. The developer can pass a token that can be interpreted by the hardware stack and the SDK will simply pass the token down to the custom tlsio interface without inspecting the value of the token. This way the actual keys never leave the hardware. + +## Symmetric Key Provisioning + +- Coming soon + +For more reading on Symmetric key information please see [Symmetric key concept doc](https://docs.microsoft.com/en-us/azure/iot-dps/concepts-symmetric-key-attestation) + +## TPM Provisioning + +- Coming soon + +For more reading on TPM information please see [TPM Attestation doc](https://docs.microsoft.com/en-us/azure/iot-dps/concepts-tpm-attestation) + +## Related documents + +[Porting guide for Azure IoT C SDK](https://github.com/Azure/azure-c-shared-utility/blob/master/devdoc/porting_guide.md) \ No newline at end of file diff --git a/provisioning_client/devdoc/using_provisioning_client.md b/provisioning_client/devdoc/using_provisioning_client.md index bb7504668b..9857e5db3c 100644 --- a/provisioning_client/devdoc/using_provisioning_client.md +++ b/provisioning_client/devdoc/using_provisioning_client.md @@ -10,6 +10,10 @@ To use the Provisioning Device client code to connect to windows or linux HSM re cmake -Duse_prov_client:BOOL=ON .. ``` +For Development scenarios, the provisioning client relies on generated test x509 certificates with a pre-generated key within [hsm_client_riot.c](https://github.com/Azure/azure-iot-sdk-c/blob/master/provisioning_client/adapters/hsm_client_riot.c) + +For Production scenarios, you need to add the USE_CUSTOM_HSM cmake flag with the full path to your custom hsm lib (see custom hsm example below). + ## Enabling Provisioning Device Client simulator For development purposes the Provisioning Device Client uses simulators to mock hardware chips functionality: diff --git a/provisioning_client/inc/azure_prov_client/prov_client_const.h b/provisioning_client/inc/azure_prov_client/prov_client_const.h index 3298504e3d..9df885649f 100644 --- a/provisioning_client/inc/azure_prov_client/prov_client_const.h +++ b/provisioning_client/inc/azure_prov_client/prov_client_const.h @@ -4,7 +4,7 @@ #ifndef PROV_CLIENT_CONST_H #define PROV_CLIENT_CONST_H -#define PROV_DEVICE_CLIENT_VERSION "1.2.12" +#define PROV_DEVICE_CLIENT_VERSION "1.3.0" static const char* const PROV_ASSIGNED_STATUS = "assigned"; static const char* const PROV_ASSIGNING_STATUS = "assigning"; diff --git a/provisioning_client/samples/prov_dev_client_ll_sample/prov_dev_client_ll_sample.c b/provisioning_client/samples/prov_dev_client_ll_sample/prov_dev_client_ll_sample.c index 1d5cac98c3..8690341c9e 100644 --- a/provisioning_client/samples/prov_dev_client_ll_sample/prov_dev_client_ll_sample.c +++ b/provisioning_client/samples/prov_dev_client_ll_sample/prov_dev_client_ll_sample.c @@ -99,7 +99,7 @@ static IOTHUBMESSAGE_DISPOSITION_RESULT receive_msg_callback(IOTHUB_MESSAGE_HAND return IOTHUBMESSAGE_ACCEPTED; } -static void registation_status_callback(PROV_DEVICE_REG_STATUS reg_status, void* user_context) +static void registration_status_callback(PROV_DEVICE_REG_STATUS reg_status, void* user_context) { (void)user_context; (void)printf("Provisioning Status: %s\r\n", ENUM_TO_STRING(PROV_DEVICE_REG_STATUS, reg_status)); @@ -225,7 +225,7 @@ int main() // set within the HSM so be cautious if setting this value //Prov_Device_SetOption(prov_device_handle, PROV_REGISTRATION_ID, "[REGISTRATION ID]"); - if (Prov_Device_LL_Register_Device(handle, register_device_callback, &user_ctx, registation_status_callback, &user_ctx) != PROV_DEVICE_RESULT_OK) + if (Prov_Device_LL_Register_Device(handle, register_device_callback, &user_ctx, registration_status_callback, &user_ctx) != PROV_DEVICE_RESULT_OK) { (void)printf("failed calling Prov_Device_LL_Register_Device\r\n"); } diff --git a/provisioning_client/samples/prov_dev_client_sample/prov_dev_client_sample.c b/provisioning_client/samples/prov_dev_client_sample/prov_dev_client_sample.c index dc8e9dddf1..ee01c0dd68 100644 --- a/provisioning_client/samples/prov_dev_client_sample/prov_dev_client_sample.c +++ b/provisioning_client/samples/prov_dev_client_sample/prov_dev_client_sample.c @@ -71,7 +71,7 @@ static const char* PROXY_ADDRESS = "127.0.0.1"; #define MESSAGES_TO_SEND 2 #define TIME_BETWEEN_MESSAGES 2 -static void registation_status_callback(PROV_DEVICE_REG_STATUS reg_status, void* user_context) +static void registration_status_callback(PROV_DEVICE_REG_STATUS reg_status, void* user_context) { (void)user_context; (void)printf("Provisioning Status: %s\r\n", ENUM_TO_STRING(PROV_DEVICE_REG_STATUS, reg_status)); @@ -160,7 +160,7 @@ int main() // set within the HSM so be cautious if setting this value //Prov_Device_SetOption(prov_device_handle, PROV_REGISTRATION_ID, "[REGISTRATION ID]"); - prov_device_result = Prov_Device_Register_Device(prov_device_handle, register_device_callback, NULL, registation_status_callback, NULL); + prov_device_result = Prov_Device_Register_Device(prov_device_handle, register_device_callback, NULL, registration_status_callback, NULL); (void)printf("\r\nRegistering Device\r\n\r\n"); do diff --git a/provisioning_client/samples/readme.md b/provisioning_client/samples/readme.md new file mode 100644 index 0000000000..d839bc935c --- /dev/null +++ b/provisioning_client/samples/readme.md @@ -0,0 +1,23 @@ +# Samples for Azure IoT Provisioning SDK + +## List of samples + +- custom_hsm_examples + + - This example shows how to create a custom HSM to retrieve the secruity information needed for the provisioning SDK to communication the the DPS Service. + +- iothub_client_sample_hsm + + - This sample show how to use the IoT hub Device Client with the device authentication system without using provisioning. + +- prov_dev_client_ll_sample + + - This sample uses the non-threaded SDK to connect the provisioning client and get the IoThub information and then connects to the iothub. This example would be for devices that require greater control over communications by calling DoWork to control the message pump. + +- prov_dev_client_sample + + - This sample uses the convenience layer SDK to connect the provisioning client and get the IoThub information. This example would be used for devices that don't want to deal with calling DoWork for communication + +### Running Samples + +You don't need any special hardware to test the samples. After you create your [Device Provisioning hub](https://docs.microsoft.com/en-us/azure/iot-dps/quick-setup-auto-provision), you can just follow the [provisioning SDK documentation](https://github.com/Azure/azure-iot-sdk-c/blob/master/provisioning_client/devdoc/using_provisioning_client.md). diff --git a/provisioning_client/src/iothub_auth_client.c b/provisioning_client/src/iothub_auth_client.c index fde56ceab2..1afadc8dc1 100644 --- a/provisioning_client/src/iothub_auth_client.c +++ b/provisioning_client/src/iothub_auth_client.c @@ -5,7 +5,7 @@ #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sastoken.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/strings.h" @@ -64,33 +64,33 @@ static int sign_sas_data(IOTHUB_SECURITY_INFO* security_info, const char* payloa } else { + BUFFER_HANDLE decoded_key = NULL; + BUFFER_HANDLE output_hash = NULL; + char* symmetrical_key = security_info->hsm_client_get_symm_key(security_info->hsm_client_handle); if (symmetrical_key == NULL) { LogError("Failed getting asymmetrical key"); result = __FAILURE__; } + else if ((decoded_key = Azure_Base64_Decode(symmetrical_key)) == NULL) + { + LogError("Failed decoding symmetrical key"); + result = __FAILURE__; + } + else if ((output_hash = BUFFER_new()) == NULL) + { + LogError("Failed allocating output hash buffer"); + result = __FAILURE__; + } else { - BUFFER_HANDLE decoded_key; - BUFFER_HANDLE output_hash; + size_t decoded_key_len = BUFFER_length(decoded_key); + const unsigned char* decoded_key_bytes = BUFFER_u_char(decoded_key); - if ((decoded_key = Base64_Decoder(symmetrical_key)) == NULL) - { - LogError("Failed decoding symmetrical key"); - result = __FAILURE__; - } - else if ((output_hash = BUFFER_new()) == NULL) - { - LogError("Failed allocating output hash buffer"); - BUFFER_delete(decoded_key); - result = __FAILURE__; - } - else if (HMACSHA256_ComputeHash(BUFFER_u_char(decoded_key), BUFFER_length(decoded_key), (const unsigned char*)payload, payload_len, output_hash) != HMACSHA256_OK) + if (HMACSHA256_ComputeHash(decoded_key_bytes, decoded_key_len, (const unsigned char*)payload, payload_len, output_hash) != HMACSHA256_OK) { LogError("Failed computing HMAC Hash"); - BUFFER_delete(decoded_key); - BUFFER_delete(output_hash); result = __FAILURE__; } else @@ -107,12 +107,15 @@ static int sign_sas_data(IOTHUB_SECURITY_INFO* security_info, const char* payloa memcpy(*output, output_data, *len); result = 0; } - BUFFER_delete(decoded_key); - BUFFER_delete(output_hash); + } - free(symmetrical_key); } + + BUFFER_delete(decoded_key); + BUFFER_delete(output_hash); + free(symmetrical_key); } + return result; } @@ -171,7 +174,7 @@ IOTHUB_SECURITY_HANDLE iothub_device_auth_create() } } #endif -#if defined(HSM_TYPE_SYMM_KEY) +#if defined(HSM_TYPE_SYMM_KEY) || defined(HSM_AUTH_TYPE_CUSTOM) if (result != NULL && iothub_security_t == IOTHUB_SECURITY_TYPE_SYMMETRIC_KEY) { result->cred_type = AUTH_TYPE_SYMM_KEY; @@ -339,7 +342,7 @@ CREDENTIAL_RESULT* iothub_device_auth_generate_credentials(IOTHUB_SECURITY_HANDL STRING_HANDLE signature = NULL; if (handle->base64_encode_signature == true) { - signature = Base64_Encode_Bytes(data_value, data_len); + signature = Azure_Base64_Encode_Bytes(data_value, data_len); } else { diff --git a/provisioning_client/src/prov_auth_client.c b/provisioning_client/src/prov_auth_client.c index 05bef647d1..0ef4e86d5f 100644 --- a/provisioning_client/src/prov_auth_client.c +++ b/provisioning_client/src/prov_auth_client.c @@ -5,7 +5,7 @@ #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/xlogging.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/base32.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/sha.h" @@ -160,33 +160,33 @@ static int sign_sas_data(PROV_AUTH_INFO* auth_info, const char* payload, unsigne } else { + BUFFER_HANDLE decoded_key = NULL; + BUFFER_HANDLE output_hash = NULL; + char* symmetrical_key = auth_info->hsm_client_get_symm_key(auth_info->hsm_client_handle); if (symmetrical_key == NULL) { LogError("Failed getting asymmetrical key"); result = __FAILURE__; } + else if ((decoded_key = Azure_Base64_Decode(symmetrical_key)) == NULL) + { + LogError("Failed decoding symmetrical key"); + result = __FAILURE__; + } + else if ((output_hash = BUFFER_new()) == NULL) + { + LogError("Failed allocating output hash buffer"); + result = __FAILURE__; + } else { - BUFFER_HANDLE decoded_key; - BUFFER_HANDLE output_hash; + size_t decoded_key_len = BUFFER_length(decoded_key); + const unsigned char* decoded_key_bytes = BUFFER_u_char(decoded_key); - if ((decoded_key = Base64_Decoder(symmetrical_key)) == NULL) - { - LogError("Failed decoding symmetrical key"); - result = __FAILURE__; - } - else if ((output_hash = BUFFER_new()) == NULL) - { - LogError("Failed allocating output hash buffer"); - BUFFER_delete(decoded_key); - result = __FAILURE__; - } - else if (HMACSHA256_ComputeHash(BUFFER_u_char(decoded_key), BUFFER_length(decoded_key), (const unsigned char*)payload, payload_len, output_hash) != HMACSHA256_OK) + if (HMACSHA256_ComputeHash(decoded_key_bytes, decoded_key_len, (const unsigned char*)payload, payload_len, output_hash) != HMACSHA256_OK) { LogError("Failed computing HMAC Hash"); - BUFFER_delete(decoded_key); - BUFFER_delete(output_hash); result = __FAILURE__; } else @@ -203,11 +203,13 @@ static int sign_sas_data(PROV_AUTH_INFO* auth_info, const char* payload, unsigne memcpy(*output, output_data, *len); result = 0; } - BUFFER_delete(decoded_key); - BUFFER_delete(output_hash); + } - free(symmetrical_key); } + + BUFFER_delete(decoded_key); + BUFFER_delete(output_hash); + free(symmetrical_key); } return result; } @@ -224,6 +226,7 @@ PROV_AUTH_HANDLE prov_auth_create() { memset(result, 0, sizeof(PROV_AUTH_INFO) ); SECURE_DEVICE_TYPE sec_type = prov_dev_security_get_type(); +#if defined(HSM_TYPE_SAS_TOKEN) || defined(HSM_AUTH_TYPE_CUSTOM) if (sec_type == SECURE_DEVICE_TYPE_TPM) { /* Codes_SRS_PROV_AUTH_CLIENT_07_003: [ prov_auth_create shall validate the specified secure enclave interface to ensure. ] */ @@ -244,7 +247,9 @@ PROV_AUTH_HANDLE prov_auth_create() result = NULL; } } - else if (sec_type == SECURE_DEVICE_TYPE_X509) +#endif +#if defined(HSM_TYPE_X509) || defined(HSM_AUTH_TYPE_CUSTOM) + if (sec_type == SECURE_DEVICE_TYPE_X509) { /* Codes_SRS_PROV_AUTH_CLIENT_07_003: [ prov_auth_create shall validate the specified secure enclave interface to ensure. ] */ result->sec_type = PROV_AUTH_TYPE_X509; @@ -262,9 +267,10 @@ PROV_AUTH_HANDLE prov_auth_create() result = NULL; } } - else +#endif +#if defined(HSM_TYPE_SYMM_KEY) || defined(HSM_AUTH_TYPE_CUSTOM) + if (sec_type == SECURE_DEVICE_TYPE_SYMMETRIC_KEY) { -#if defined(HSM_TYPE_SYMM_KEY) result->sec_type = PROV_AUTH_TYPE_KEY; const HSM_CLIENT_KEY_INTERFACE* key_interface = hsm_client_key_interface(); if ((key_interface == NULL) || @@ -279,13 +285,20 @@ PROV_AUTH_HANDLE prov_auth_create() free(result); result = NULL; } -#else - LogError("Invalid secure device type was specified"); - result = NULL; -#endif } +#endif - if (result != NULL) + if (result == NULL) + { + LogError("Error allocating result or else unsupported security type %d", sec_type); + } + else if (result->hsm_client_create == NULL) + { + LogError("hsm_client_create is not a valid address"); + free(result); + result = NULL; + } + else { /* Codes_SRS_PROV_AUTH_CLIENT_07_004: [ prov_auth_create shall call hsm_client_create on the secure enclave interface. ] */ if ((result->hsm_client_handle = result->hsm_client_create() ) == NULL) @@ -560,7 +573,7 @@ char* prov_auth_construct_sas_token(PROV_AUTH_HANDLE handle, const char* token_s STRING_HANDLE urlEncodedSignature; STRING_HANDLE base64Signature; STRING_HANDLE sas_token_handle; - if ((base64Signature = Base64_Encode_Bytes(data_value, data_len)) == NULL) + if ((base64Signature = Azure_Base64_Encode_Bytes(data_value, data_len)) == NULL) { result = NULL; LogError("Failure constructing base64 encoding."); @@ -650,68 +663,3 @@ char* prov_auth_get_alias_key(PROV_AUTH_HANDLE handle) } return result; } - -#if 0 -char* prov_auth_get_signer_cert(PROV_AUTH_HANDLE handle) -{ - char* result; - if (handle == NULL) - { - /* Codes_SRS_SECURE_ENCLAVE_CLIENT_07_036: [ If handle or key are NULL prov_auth_get_signer_cert shall return a non-zero value. ] */ - LogError("Invalid handle parameter"); - result = NULL; - } - else if (handle->sec_type != PROV_AUTH_TYPE_X509) - { - /* Codes_SRS_SECURE_ENCLAVE_CLIENT_07_038: [ If the sec_type is not PROV_AUTH_TYPE_X509, prov_auth_get_signer_cert shall return NULL. ] */ - LogError("Invalid type for operation"); - result = NULL; - } - else - { - /* Codes_SRS_SECURE_ENCLAVE_CLIENT_07_037: [ prov_auth_get_signer_cert shall import the specified signer cert into the client using hsm_client_get_signer_cert secure enclave function. ] */ - result = handle->hsm_client_get_signer_cert(handle->sec_dev_handle); - } - return result; -} - -char* prov_auth_get_root_cert(PROV_AUTH_HANDLE handle) -{ - char* result; - if (handle == NULL) - { - LogError("Invalid handle parameter"); - result = NULL; - } - else if (handle->sec_type != PROV_AUTH_TYPE_X509) - { - LogError("Invalid type for operation"); - result = NULL; - } - else - { - result = handle->hsm_client_get_root_cert(handle->sec_dev_handle); - } - return result; -} - -char* prov_auth_get_root_key(PROV_AUTH_HANDLE handle) -{ - char* result; - if (handle == NULL) - { - LogError("Invalid handle parameter"); - result = NULL; - } - else if (handle->sec_type != PROV_AUTH_TYPE_X509) - { - LogError("Invalid type for operation"); - result = NULL; - } - else - { - result = handle->hsm_client_get_root_key(handle->sec_dev_handle); - } - return result; -} -#endif diff --git a/provisioning_client/src/prov_device_client.c b/provisioning_client/src/prov_device_client.c index b1756264c1..b0a5d4b69e 100644 --- a/provisioning_client/src/prov_device_client.c +++ b/provisioning_client/src/prov_device_client.c @@ -101,6 +101,7 @@ PROV_DEVICE_HANDLE Prov_Device_Create(const char* uri, const char* id_scope, PRO } else { + memset(result, 0, sizeof(PROV_DEVICE_INSTANCE) ); /* Codes_SRS_PROV_DEVICE_CLIENT_12_004: [ The function shall initialize the Lock. ] */ result->LockHandle = Lock_Init(); if (result->LockHandle == NULL) @@ -117,6 +118,7 @@ PROV_DEVICE_HANDLE Prov_Device_Create(const char* uri, const char* id_scope, PRO /* Codes_SRS_PROV_DEVICE_CLIENT_12_007: [ The function shall initialize the result datastructure. ] */ result->ThreadHandle = NULL; result->StopThread = 0; + result->do_work_freq_ms = DO_WORK_FREQ_DEFAULT; } } } @@ -234,7 +236,7 @@ PROV_DEVICE_RESULT Prov_Device_SetOption(PROV_DEVICE_HANDLE prov_device_handle, /* Codes_SRS_PROV_DEVICE_CLIENT_12_023: [ The function shall call the LL layer Prov_Device_LL_SetOption with the given parameters and return with the result. ] */ PROV_DEVICE_INSTANCE* prov_device_instance = (PROV_DEVICE_INSTANCE*)prov_device_handle; - /* Codes_SRS_PROV_DEVICE_CLIENT_41_002: [ `Prov_Device_SetOption` shall be made thread-safe by using the lock created in `Prov_Device_Create`. ] */ + /* Codes_SRS_PROV_DEVICE_CLIENT_41_002: [ `Prov_Device_SetOption` shall be made thread-safe by using the lock created in `Prov_Device_Create`. ] */ if (Lock(prov_device_instance->LockHandle) != LOCK_OK) { /* Codes_SRS_PROV_DEVICE_CLIENT_41_003: [ If acquiring the lock fails, `Prov_Device_SetOption` shall return `IOTHUB_CLIENT_ERROR`. ] */ @@ -243,7 +245,7 @@ PROV_DEVICE_RESULT Prov_Device_SetOption(PROV_DEVICE_HANDLE prov_device_handle, } else { - /* Codes_SRS_PROV_DEVICE_CLIENT_41_001: [ If parameter `optionName` is `OPTION_DO_WORK_FREQUENCY_IN_MS` then `IoTHubClientCore_SetOption` shall set `do_work_freq_ms` parameter of `prov_device_instance` ] */ + /* Codes_SRS_PROV_DEVICE_CLIENT_41_001: [ If parameter `optionName` is `OPTION_DO_WORK_FREQUENCY_IN_MS` then `IoTHubClientCore_SetOption` shall set `do_work_freq_ms` parameter of `prov_device_instance` ] */ if (strcmp(OPTION_DO_WORK_FREQUENCY_IN_MS, optionName) == 0) { prov_device_instance->do_work_freq_ms = *((uint16_t *)value); diff --git a/provisioning_client/src/prov_device_ll_client.c b/provisioning_client/src/prov_device_ll_client.c index eeb35a85c8..f15d4f1194 100644 --- a/provisioning_client/src/prov_device_ll_client.c +++ b/provisioning_client/src/prov_device_ll_client.c @@ -13,7 +13,7 @@ #include "azure_c_shared_utility/uniqueid.h" #include "azure_c_shared_utility/sastoken.h" #include "azure_c_shared_utility/crt_abstractions.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/tickcounter.h" @@ -328,7 +328,7 @@ static PROV_JSON_INFO* prov_transport_process_json_reply(const char* json_docume else { const char* nonce_field = json_value_get_string(auth_key); - if ((result->authorization_key = Base64_Decoder(nonce_field)) == NULL) + if ((result->authorization_key = Azure_Base64_Decode(nonce_field)) == NULL) { LogError("failure creating buffer nonce field"); prov_info->error_reason = PROV_DEVICE_RESULT_MEMORY; @@ -395,7 +395,7 @@ static PROV_JSON_INFO* prov_transport_process_json_reply(const char* json_docume else { const char* nonce_field = json_value_get_string(auth_key); - if ((result->authorization_key = Base64_Decoder(nonce_field)) == NULL) + if ((result->authorization_key = Azure_Base64_Decode(nonce_field)) == NULL) { LogError("failure creating buffer nonce field"); prov_info->error_reason = PROV_DEVICE_RESULT_MEMORY; @@ -983,7 +983,7 @@ void Prov_Device_LL_DoWork(PROV_DEVICE_LL_HANDLE handle) } else { - // Check the connection + // Check the connection if (prov_info->prov_timeout > 0) { tickcounter_ms_t current_time = 0; diff --git a/provisioning_client/src/prov_sasl_tpm.c b/provisioning_client/src/prov_sasl_tpm.c index e60281508d..fe328efddf 100644 --- a/provisioning_client/src/prov_sasl_tpm.c +++ b/provisioning_client/src/prov_sasl_tpm.c @@ -7,7 +7,6 @@ #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/crt_abstractions.h" -#include "azure_c_shared_utility/base64.h" #include "azure_c_shared_utility/strings.h" #include "azure_prov_client/prov_transport.h" diff --git a/provisioning_client/src/prov_transport_amqp_client.c b/provisioning_client/src/prov_transport_amqp_client.c index 3157549c2a..87f941ee3e 100644 --- a/provisioning_client/src/prov_transport_amqp_client.c +++ b/provisioning_client/src/prov_transport_amqp_client.c @@ -68,10 +68,6 @@ static PROV_TRANSPORT_IO_INFO* amqp_transport_io(const char* fqdn, SASL_MECHANIS } else { - // provisioning requires tls 1.2 - int tls_version = 12; - xio_setoption(result->transport_handle, OPTION_TLS_VERSION, &tls_version); - if (sasl_mechanism != NULL) { const IO_INTERFACE_DESCRIPTION* saslio_interface; diff --git a/provisioning_client/src/prov_transport_amqp_common.c b/provisioning_client/src/prov_transport_amqp_common.c index 6b01c6a92a..b9fc6a3603 100644 --- a/provisioning_client/src/prov_transport_amqp_common.c +++ b/provisioning_client/src/prov_transport_amqp_common.c @@ -663,7 +663,7 @@ static int create_transport_io_object(PROV_TRANSPORT_AMQP_INFO* amqp_info) transport_proxy = NULL; } - if (amqp_info->hsm_type == TRANSPORT_HSM_TYPE_TPM) + if (amqp_info->hsm_type == TRANSPORT_HSM_TYPE_TPM || amqp_info->hsm_type == TRANSPORT_HSM_TYPE_SYMM_KEY) { sasl_mechanism = &amqp_info->sasl_handler; } diff --git a/provisioning_client/src/prov_transport_amqp_ws_client.c b/provisioning_client/src/prov_transport_amqp_ws_client.c index f8bf0b1102..184d38bd5d 100644 --- a/provisioning_client/src/prov_transport_amqp_ws_client.c +++ b/provisioning_client/src/prov_transport_amqp_ws_client.c @@ -85,12 +85,6 @@ static PROV_TRANSPORT_IO_INFO* amqp_transport_ws_io(const char* fqdn, SASL_MECHA } else { -#ifdef USE_OPENSSL - // Default to tls 1.2 - int tls_version = 12; - xio_setoption(result->transport_handle, OPTION_TLS_VERSION, &tls_version); -#endif - if (sasl_mechanism != NULL) { const IO_INTERFACE_DESCRIPTION* saslio_interface; diff --git a/provisioning_client/src/prov_transport_http_client.c b/provisioning_client/src/prov_transport_http_client.c index 271735404e..38e7adfd84 100644 --- a/provisioning_client/src/prov_transport_http_client.c +++ b/provisioning_client/src/prov_transport_http_client.c @@ -12,7 +12,7 @@ #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/http_proxy_io.h" #include "azure_c_shared_utility/urlencode.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_prov_client/prov_transport_http_client.h" #include "azure_prov_client/internal/prov_transport_private.h" @@ -257,12 +257,12 @@ static char* construct_json_data(PROV_TRANSPORT_HTTP_INFO* http_info) { STRING_HANDLE encoded_srk = NULL; STRING_HANDLE encoded_ek; - if ((encoded_ek = Base64_Encoder(http_info->ek)) == NULL) + if ((encoded_ek = Azure_Base64_Encode(http_info->ek)) == NULL) { LogError("Failure encoding ek"); result = NULL; } - else if ((encoded_srk = Base64_Encoder(http_info->srk)) == NULL) + else if ((encoded_srk = Azure_Base64_Encode(http_info->srk)) == NULL) { LogError("Failure encoding srk"); result = NULL; @@ -1037,21 +1037,28 @@ int prov_transport_http_set_trace(PROV_DEVICE_TRANSPORT_HANDLE handle, bool trac else { PROV_TRANSPORT_HTTP_INFO* http_info = (PROV_TRANSPORT_HTTP_INFO*)handle; - if (http_info->hsm_type == TRANSPORT_HSM_TYPE_X509) + if (trace_on) { - http_info->log_trace = trace_on; - if (http_info->http_client != NULL) + if (http_info->hsm_type == TRANSPORT_HSM_TYPE_X509) { - /* Codes_PROV_TRANSPORT_HTTP_CLIENT_07_041: [ If the http client is not NULL, prov_transport_http_set_trace shall set the http client log trace function with the specified trace_on flag. ] */ - (void)uhttp_client_set_trace(http_info->http_client, http_info->log_trace, http_info->log_trace); + http_info->log_trace = trace_on; + if (http_info->http_client != NULL) + { + /* Codes_PROV_TRANSPORT_HTTP_CLIENT_07_041: [ If the http client is not NULL, prov_transport_http_set_trace shall set the http client log trace function with the specified trace_on flag. ] */ + (void)uhttp_client_set_trace(http_info->http_client, http_info->log_trace, http_info->log_trace); + } + /* Codes_PROV_TRANSPORT_HTTP_CLIENT_07_042: [ On success prov_transport_http_set_trace shall return zero. ] */ + result = 0; + } + else + { + LogError("Unable to enable logging when not using x509 certificates"); + result = __FAILURE__; } - /* Codes_PROV_TRANSPORT_HTTP_CLIENT_07_042: [ On success prov_transport_http_set_trace shall return zero. ] */ - result = 0; } else { - LogError("Unable to enable logging when not using x509 certificates"); - result = __FAILURE__; + result = 0; } } return result; diff --git a/provisioning_client/src/prov_transport_mqtt_client.c b/provisioning_client/src/prov_transport_mqtt_client.c index cd2d52f874..2a9b4cd8e2 100644 --- a/provisioning_client/src/prov_transport_mqtt_client.c +++ b/provisioning_client/src/prov_transport_mqtt_client.c @@ -53,14 +53,6 @@ static XIO_HANDLE mqtt_transport_io(const char* fqdn, const HTTP_PROXY_OPTIONS* LogError("failed calling xio_create on underlying io"); result = NULL; } - else - { -#ifdef USE_OPENSSL - // requires tls 1.2 - int tls_version = 12; - xio_setoption(result, OPTION_TLS_VERSION, &tls_version); -#endif - } } /* Codes_PROV_TRANSPORT_MQTT_CLIENT_07_014: [ On success mqtt_transport_io shall return allocated XIO_HANDLE. ] */ return result; diff --git a/provisioning_client/src/prov_transport_mqtt_common.c b/provisioning_client/src/prov_transport_mqtt_common.c index 4175bd8821..8398cebc98 100644 --- a/provisioning_client/src/prov_transport_mqtt_common.c +++ b/provisioning_client/src/prov_transport_mqtt_common.c @@ -893,7 +893,7 @@ void prov_transport_common_mqtt_dowork(PROV_DEVICE_TRANSPORT_HANDLE handle) if (create_connection(mqtt_info) != 0) { /* Tests_PROV_TRANSPORT_MQTT_COMMON_07_049: [ If any error is encountered prov_transport_common_mqtt_dowork shall set the mqtt_state to MQTT_STATE_ERROR and the transport_state to TRANSPORT_CLIENT_STATE_ERROR. ] */ - LogError("unable to create amqp connection"); + LogError("unable to create mqtt connection"); mqtt_info->mqtt_state = MQTT_STATE_ERROR; mqtt_info->transport_state = TRANSPORT_CLIENT_STATE_ERROR; } @@ -936,7 +936,7 @@ void prov_transport_common_mqtt_dowork(PROV_DEVICE_TRANSPORT_HANDLE handle) } else { - /* Codes_PROV_TRANSPORT_AMQP_COMMON_07_054: [ Upon successful sending of a TRANSPORT_CLIENT_STATE_REG_SEND message, prov_transport_common_mqtt_dowork shall set the transport_state to TRANSPORT_CLIENT_STATE_REG_SENT ] */ + /* Codes_PROV_TRANSPORT_MQTT_COMMON_07_054: [ Upon successful sending of a TRANSPORT_CLIENT_STATE_REG_SEND message, prov_transport_common_mqtt_dowork shall set the transport_state to TRANSPORT_CLIENT_STATE_REG_SENT ] */ mqtt_info->transport_state = TRANSPORT_CLIENT_STATE_REG_SENT; } break; diff --git a/provisioning_client/src/prov_transport_mqtt_ws_client.c b/provisioning_client/src/prov_transport_mqtt_ws_client.c index 2f91818eff..097ca4a776 100644 --- a/provisioning_client/src/prov_transport_mqtt_ws_client.c +++ b/provisioning_client/src/prov_transport_mqtt_ws_client.c @@ -69,14 +69,6 @@ static XIO_HANDLE mqtt_transport_ws_io(const char* fqdn, const HTTP_PROXY_OPTION { LogError("failed calling xio_create on underlying io"); } - else - { -#ifdef USE_OPENSSL - // requires tls 1.2 - int tls_version = 12; - xio_setoption(result, OPTION_TLS_VERSION, &tls_version); -#endif - } } /* Codes_PROV_TRANSPORT_MQTT_WS_CLIENT_07_014: [ On success mqtt_transport_ws_io shall return an allocated XIO_HANDLE. ] */ return result; diff --git a/provisioning_client/src/sec_device_module_tpm.c b/provisioning_client/src/sec_device_module_tpm.c index 2130e2c5b0..49ac013c6a 100644 --- a/provisioning_client/src/sec_device_module_tpm.c +++ b/provisioning_client/src/sec_device_module_tpm.c @@ -5,7 +5,7 @@ #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sastoken.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/strings.h" @@ -366,7 +366,7 @@ void* dev_auth_tpm_generate_credentials(CONCRETE_XDA_HANDLE handle, const DEVICE STRING_HANDLE urlEncodedSignature; STRING_HANDLE base64Signature; STRING_HANDLE sas_token_handle; - if ((base64Signature = Base64_Encode_Bytes(hmac_buffer, hmac_len)) == NULL) + if ((base64Signature = Azure_Base64_Encode_Bytes(hmac_buffer, hmac_len)) == NULL) { result = NULL; LogError("Failure constructing base64 encoding."); @@ -610,7 +610,7 @@ char* dev_auth_tpm_get_registration_key(CONCRETE_XDA_HANDLE handle) } else { - STRING_HANDLE encoded_key = Base64_Encode_Bytes(msg_digest, SHA256HashSize); + STRING_HANDLE encoded_key = Azure_Base64_Encode_Bytes(msg_digest, SHA256HashSize); if (encoded_key == NULL) { LogError("Failed base64 encoding"); diff --git a/provisioning_client/src/secure_device_tpm.c b/provisioning_client/src/secure_device_tpm.c index 61c51a0db2..8f2ea81050 100644 --- a/provisioning_client/src/secure_device_tpm.c +++ b/provisioning_client/src/secure_device_tpm.c @@ -6,7 +6,7 @@ #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/sastoken.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/strings.h" @@ -420,7 +420,7 @@ static BUFFER_HANDLE decrypt_data(SEC_DEVICE_INFO* sec_info, const unsigned char curr_pos += enc_data_size; act_size -= enc_data_size; - // decrypts encrypted symmetric key ‘encSecret‘ and returns it as 'tpm_blob'. + // decrypts encrypted symmetric key ?encSecret? and returns it as 'tpm_blob'. // Later 'tpm_blob' is used as the inner wrapper key for import of the HMAC key blob. if (TPM2_ActivateCredential(&sec_info->tpm_device, &NullPwSession, &ek_sess, TPM_20_SRK_HANDLE, TPM_20_EK_HANDLE, &tpm_blob, &tpm_enc_secret, &inner_wrap_key) != TPM_RC_SUCCESS) { @@ -604,7 +604,7 @@ char* secure_dev_tpm_get_endorsement_key(SEC_DEVICE_HANDLE handle) unsigned char* data_pos = data_bytes; /* Codes_SRS_SECURE_DEVICE_TPM_07_014: [ secure_dev_tpm_get_endorsement_key shall allocate and return the Endorsement Key. ] */ uint32_t data_length = TPM2B_PUBLIC_Marshal(&handle->ek_pub, &data_pos, NULL); - STRING_HANDLE encoded_ek = Base64_Encode_Bytes(data_bytes, data_length); + STRING_HANDLE encoded_ek = Azure_Base64_Encode_Bytes(data_bytes, data_length); if (encoded_ek == NULL) { /* Codes_SRS_SECURE_DEVICE_TPM_07_015: [ If a failure is encountered, secure_dev_tpm_get_endorsement_key shall return NULL. ] */ @@ -646,7 +646,7 @@ char* secure_dev_tpm_get_storage_key(SEC_DEVICE_HANDLE handle) unsigned char* data_pos = data_bytes; /* Codes_SRS_SECURE_DEVICE_TPM_07_018: [ secure_dev_tpm_get_storage_key shall allocate and return the Storage Root Key. ] */ uint32_t data_length = TPM2B_PUBLIC_Marshal(&handle->srk_pub, &data_pos, NULL); - STRING_HANDLE encoded_srk = Base64_Encode_Bytes(data_bytes, data_length); + STRING_HANDLE encoded_srk = Azure_Base64_Encode_Bytes(data_bytes, data_length); if (encoded_srk == NULL) { /* Codes_SRS_SECURE_DEVICE_TPM_07_019: [ If any failure is encountered, secure_dev_tpm_get_storage_key shall return NULL. ] */ diff --git a/provisioning_client/tests/common_prov_e2e/common_prov_e2e.c b/provisioning_client/tests/common_prov_e2e/common_prov_e2e.c index c4c939a365..e481a344bc 100644 --- a/provisioning_client/tests/common_prov_e2e/common_prov_e2e.c +++ b/provisioning_client/tests/common_prov_e2e/common_prov_e2e.c @@ -19,9 +19,9 @@ #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/macro_utils.h" #include "azure_c_shared_utility/xlogging.h" -#include "azure_c_shared_utility/base64.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/uniqueid.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_prov_client/prov_device_ll_client.h" #include "azure_prov_client/prov_security_factory.h" @@ -142,8 +142,8 @@ void create_tpm_enrollment_device(const char* prov_conn_string, bool use_tracing BUFFER_HANDLE ek_handle = prov_auth_get_endorsement_key(auth_handle); ASSERT_IS_NOT_NULL(ek_handle, "Failure prov_auth_get_endorsement_key"); - STRING_HANDLE ek_value = Base64_Encoder(ek_handle); - ASSERT_IS_NOT_NULL(ek_value, "Failure Base64_Encoder Endorsement key"); + STRING_HANDLE ek_value = Azure_Base64_Encode(ek_handle); + ASSERT_IS_NOT_NULL(ek_value, "Failure Base64_Encode Endorsement key"); ATTESTATION_MECHANISM_HANDLE attest_handle = attestationMechanism_createWithTpm(STRING_c_str(ek_value), NULL); ASSERT_IS_NOT_NULL(attest_handle, "Failure attestationMechanism_createWithTpm"); diff --git a/provisioning_client/tests/device_auth_emulator_ut/device_auth_emulator_ut.c b/provisioning_client/tests/device_auth_emulator_ut/device_auth_emulator_ut.c index cacb377884..f2b1eb7283 100644 --- a/provisioning_client/tests/device_auth_emulator_ut/device_auth_emulator_ut.c +++ b/provisioning_client/tests/device_auth_emulator_ut/device_auth_emulator_ut.c @@ -31,7 +31,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/sastoken.h" #include "azure_c_shared_utility/agenttime.h" #include "azure_c_shared_utility/buffer_.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "openssl/rsa.h" #include "openssl/pem.h" @@ -138,7 +138,7 @@ static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code) ASSERT_FAIL(temp_str); } -static BUFFER_HANDLE my_Base64_Decoder(const char* source) +static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); @@ -268,8 +268,8 @@ BEGIN_TEST_SUITE(device_auth_emulator_ut) REGISTER_GLOBAL_MOCK_FAIL_RETURN(BUFFER_build, __LINE__); REGISTER_GLOBAL_MOCK_HOOK(BUFFER_delete, my_BUFFER_delete); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); REGISTER_GLOBAL_MOCK_FAIL_RETURN(BIO_new_mem_buf, NULL); REGISTER_GLOBAL_MOCK_RETURN(BIO_new_mem_buf, TEST_BIO_HANDLE); @@ -425,11 +425,11 @@ BEGIN_TEST_SUITE(device_auth_emulator_ut) .IgnoreArgument_object(); STRICT_EXPECTED_CALL(json_value_get_string(IGNORED_PTR_ARG)) .IgnoreArgument_value(); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)) + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)) .IgnoreArgument_source(); STRICT_EXPECTED_CALL(json_value_get_string(IGNORED_PTR_ARG)) .IgnoreArgument_value(); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)) + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)) .IgnoreArgument_source(); STRICT_EXPECTED_CALL(json_value_get_string(IGNORED_PTR_ARG)) .IgnoreArgument_value(); @@ -438,7 +438,7 @@ BEGIN_TEST_SUITE(device_auth_emulator_ut) .IgnoreArgument_source(); STRICT_EXPECTED_CALL(json_value_get_string(IGNORED_PTR_ARG)) .IgnoreArgument_value(); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)) + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)) .IgnoreArgument_source(); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)) diff --git a/provisioning_client/tests/dps_client_e2e/dps_client_e2e.c b/provisioning_client/tests/dps_client_e2e/dps_client_e2e.c index 2b54e18356..4f72cfea02 100644 --- a/provisioning_client/tests/dps_client_e2e/dps_client_e2e.c +++ b/provisioning_client/tests/dps_client_e2e/dps_client_e2e.c @@ -14,7 +14,7 @@ #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/macro_utils.h" #include "azure_c_shared_utility/xlogging.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_prov_client/prov_device_ll_client.h" #include "azure_prov_client/prov_security_factory.h" @@ -170,8 +170,8 @@ static void create_tpm_enrollment_device() BUFFER_HANDLE ek_handle = prov_auth_get_endorsement_key(auth_handle); ASSERT_IS_NOT_NULL(ek_handle, "Failure prov_auth_get_endorsement_key"); - STRING_HANDLE ek_value = Base64_Encoder(ek_handle); - ASSERT_IS_NOT_NULL(ek_value, "Failure Base64_Encoder Endorsement key"); + STRING_HANDLE ek_value = Base64_Encode(ek_handle); + ASSERT_IS_NOT_NULL(ek_value, "Failure Base64_Encode Endorsement key"); ATTESTATION_MECHANISM_HANDLE attest_handle = attestationMechanism_createWithTpm(STRING_c_str(ek_value), NULL); ASSERT_IS_NOT_NULL(attest_handle, "Failure attestationMechanism_createWithTpm"); @@ -208,8 +208,8 @@ static void create_x509_enrollment_device() char* x509_cert = prov_auth_get_certificate(auth_handle); ASSERT_IS_NOT_NULL(x509_cert, "Failure prov_auth_get_certificate"); - STRING_HANDLE base64_cert = Base64_Encode_Bytes((const unsigned char*)x509_cert, strlen(x509_cert)); - ASSERT_IS_NOT_NULL(base64_cert, "Failure Base64_Encode_Bytes"); + STRING_HANDLE base64_cert = Azure_Base64_Encode_Bytes((const unsigned char*)x509_cert, strlen(x509_cert)); + ASSERT_IS_NOT_NULL(base64_cert, "Failure Azure_Base64_Encode_Bytes"); ATTESTATION_MECHANISM_HANDLE attest_handle = attestationMechanism_createWithX509ClientCert(STRING_c_str(base64_cert), NULL); ASSERT_IS_NOT_NULL(attest_handle, "Failure hsm_client_riot_get_certificate "); diff --git a/provisioning_client/tests/hsm_client_http_edge_ut/hsm_client_http_edge_ut.c b/provisioning_client/tests/hsm_client_http_edge_ut/hsm_client_http_edge_ut.c index 6370949640..742cea4655 100644 --- a/provisioning_client/tests/hsm_client_http_edge_ut/hsm_client_http_edge_ut.c +++ b/provisioning_client/tests/hsm_client_http_edge_ut/hsm_client_http_edge_ut.c @@ -69,7 +69,7 @@ static void _Bool_ToString(char* string, size_t bufferSize, _Bool val) #include "azure_c_shared_utility/socketio.h" #include "azure_uhttp_c/uhttp.h" #include "azure_c_shared_utility/envvariable.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/urlencode.h" #include "parson.h" @@ -329,8 +329,8 @@ TEST_SUITE_INITIALIZE(suite_init) REGISTER_GLOBAL_MOCK_RETURN(URL_Encode, TEST_STRING_HANDLE1); REGISTER_GLOBAL_MOCK_FAIL_RETURN(URL_Encode, NULL); - REGISTER_GLOBAL_MOCK_RETURN(Base64_Encode_Bytes, TEST_STRING_HANDLE2); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_RETURN(Azure_Base64_Encode_Bytes, TEST_STRING_HANDLE2); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); REGISTER_GLOBAL_MOCK_RETURN(STRING_c_str, TEST_STRING_1); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_c_str, NULL); @@ -558,7 +558,7 @@ static void set_expected_calls_construct_json_signing_blob() STRICT_EXPECTED_CALL(STRING_concat(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(json_value_init_object()); STRICT_EXPECTED_CALL(json_value_get_object(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(json_object_set_string(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); diff --git a/provisioning_client/tests/hsm_client_tpm_ut/hsm_client_tpm_ut.c b/provisioning_client/tests/hsm_client_tpm_ut/hsm_client_tpm_ut.c index 36ead1ef75..f1bde1d84b 100644 --- a/provisioning_client/tests/hsm_client_tpm_ut/hsm_client_tpm_ut.c +++ b/provisioning_client/tests/hsm_client_tpm_ut/hsm_client_tpm_ut.c @@ -39,7 +39,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/sastoken.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/urlencode.h" @@ -103,13 +103,13 @@ static int my_mallocAndStrcpy_s(char** destination, const char* source) return 0; } -/*static BUFFER_HANDLE my_Base64_Decoder(const char* source) +/*static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); }*/ -STRING_HANDLE my_Base64_Encode_Bytes(const unsigned char* source, size_t size) +STRING_HANDLE my_Azure_Base64_Encode_Bytes(const unsigned char* source, size_t size) { (void)source; (void)size; @@ -204,8 +204,8 @@ BEGIN_TEST_SUITE(hsm_client_tpm_ut) REGISTER_GLOBAL_MOCK_RETURN(SignData, TEST_BUFFER_SIZE); REGISTER_GLOBAL_MOCK_FAIL_RETURN(SignData, 0); - //REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - //REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + //REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + //REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); //REGISTER_GLOBAL_MOCK_HOOK(BUFFER_create, my_BUFFER_create); //REGISTER_GLOBAL_MOCK_FAIL_RETURN(BUFFER_create, NULL); @@ -215,8 +215,8 @@ BEGIN_TEST_SUITE(hsm_client_tpm_ut) REGISTER_GLOBAL_MOCK_RETURN(STRING_c_str, TEST_STRING_VALUE); REGISTER_GLOBAL_MOCK_HOOK(STRING_delete, my_STRING_delete); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encode_Bytes, my_Base64_Encode_Bytes); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode_Bytes, my_Azure_Base64_Encode_Bytes); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc); REGISTER_GLOBAL_MOCK_FAIL_RETURN(gballoc_malloc, NULL); diff --git a/provisioning_client/tests/iothub_auth_client_ut/iothub_auth_client_ut.c b/provisioning_client/tests/iothub_auth_client_ut/iothub_auth_client_ut.c index 472b877dc5..4d5adf3064 100644 --- a/provisioning_client/tests/iothub_auth_client_ut/iothub_auth_client_ut.c +++ b/provisioning_client/tests/iothub_auth_client_ut/iothub_auth_client_ut.c @@ -33,7 +33,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/sastoken.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/hmacsha256.h" @@ -107,7 +107,7 @@ IMPLEMENT_UMOCK_C_ENUM_TYPE(IOTHUB_SECURITY_TYPE, IOTHUB_SECURITY_TYPE_VALUES); TEST_DEFINE_ENUM_TYPE(HMACSHA256_RESULT, HMACSHA256_RESULT); IMPLEMENT_UMOCK_C_ENUM_TYPE(HMACSHA256_RESULT, HMACSHA256_RESULT); -static const HSM_CLIENT_TPM_INTERFACE test_tpm_interface = +static const HSM_CLIENT_TPM_INTERFACE test_tpm_interface = { hsm_client_create, hsm_client_destroy, @@ -164,7 +164,7 @@ static const HSM_CLIENT_HTTP_EDGE_INTERFACE test_http_edge_interface = }; #endif -static BUFFER_HANDLE my_Base64_Decoder(const char* source) +static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); @@ -253,7 +253,7 @@ static int my_mallocAndStrcpy_s(char** destination, const char* source) return 0; } -static STRING_HANDLE my_Base64_Encode_Bytes(const unsigned char* source, size_t length) +static STRING_HANDLE my_Azure_Base64_Encode_Bytes(const unsigned char* source, size_t length) { (void)source; (void)length; @@ -349,8 +349,8 @@ BEGIN_TEST_SUITE(iothub_auth_client_ut) REGISTER_GLOBAL_MOCK_HOOK(mallocAndStrcpy_s, my_mallocAndStrcpy_s); REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, __LINE__); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encode_Bytes, my_Base64_Encode_Bytes); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode_Bytes, my_Azure_Base64_Encode_Bytes); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); REGISTER_GLOBAL_MOCK_HOOK(URL_Encode, my_URL_Encode); REGISTER_GLOBAL_MOCK_FAIL_RETURN(URL_Encode, NULL); REGISTER_GLOBAL_MOCK_RETURN(STRING_c_str, TEST_STRING_VALUE); @@ -360,8 +360,8 @@ BEGIN_TEST_SUITE(iothub_auth_client_ut) REGISTER_GLOBAL_MOCK_HOOK(URL_EncodeString, my_URL_EncodeString); REGISTER_GLOBAL_MOCK_FAIL_RETURN(URL_EncodeString, NULL); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); REGISTER_GLOBAL_MOCK_HOOK(BUFFER_new, my_BUFFER_new); REGISTER_GLOBAL_MOCK_FAIL_RETURN(BUFFER_new, NULL); REGISTER_GLOBAL_MOCK_RETURN(BUFFER_length, TEST_DATA_LEN); @@ -373,7 +373,7 @@ BEGIN_TEST_SUITE(iothub_auth_client_ut) REGISTER_GLOBAL_MOCK_RETURN(HMACSHA256_ComputeHash, HMACSHA256_OK); REGISTER_GLOBAL_MOCK_FAIL_RETURN(HMACSHA256_ComputeHash, HMACSHA256_ERROR); - + #if defined(HSM_TYPE_X509) || defined(HSM_AUTH_TYPE_CUSTOM) REGISTER_GLOBAL_MOCK_RETURN(iothub_security_type, IOTHUB_SECURITY_TYPE_SAS); @@ -448,7 +448,7 @@ BEGIN_TEST_SUITE(iothub_auth_client_ut) if (use_key) { STRICT_EXPECTED_CALL(hsm_client_get_symmetric_key(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(BUFFER_new()); STRICT_EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)); @@ -474,7 +474,7 @@ BEGIN_TEST_SUITE(iothub_auth_client_ut) setup_sign_sas_data_mocks(use_key); if (base64_encode_signature) { - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); } else { diff --git a/provisioning_client/tests/prov_auth_client_ut/prov_auth_client_ut.c b/provisioning_client/tests/prov_auth_client_ut/prov_auth_client_ut.c index ba8a3c0d81..d9bc568d44 100644 --- a/provisioning_client/tests/prov_auth_client_ut/prov_auth_client_ut.c +++ b/provisioning_client/tests/prov_auth_client_ut/prov_auth_client_ut.c @@ -40,7 +40,7 @@ static void my_gballoc_free(void* ptr) #include "azure_prov_client/internal/prov_auth_client.h" #define ENABLE_MOCKS -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/crt_abstractions.h" @@ -114,6 +114,8 @@ static const char* TEST_TOKEN_SCOPE_VALUE = "token_scope"; static const char* TEST_KEY_NAME_VALUE = "key_value"; static const char* TEST_BASE32_VALUE = "aebagbaf"; +static const char* TEST_REGISTRATION_ID = "Registration Id"; + TEST_DEFINE_ENUM_TYPE(PROV_AUTH_RESULT, PROV_AUTH_RESULT_VALUES); IMPLEMENT_UMOCK_C_ENUM_TYPE(PROV_AUTH_RESULT, PROV_AUTH_RESULT_VALUES); @@ -123,7 +125,7 @@ IMPLEMENT_UMOCK_C_ENUM_TYPE(PROV_AUTH_TYPE, PROV_AUTH_TYPE_VALUES); TEST_DEFINE_ENUM_TYPE(HMACSHA256_RESULT, HMACSHA256_RESULT); IMPLEMENT_UMOCK_C_ENUM_TYPE(HMACSHA256_RESULT, HMACSHA256_RESULT); -static const HSM_CLIENT_TPM_INTERFACE test_tpm_interface = +static const HSM_CLIENT_TPM_INTERFACE test_tpm_interface = { secure_device_create, secure_device_destroy, @@ -252,13 +254,13 @@ static int my_mallocAndStrcpy_s(char** destination, const char* source) return 0; } -static STRING_HANDLE my_Base64_Encoder(BUFFER_HANDLE input) +static STRING_HANDLE my_Base64_Encode(BUFFER_HANDLE input) { (void)input; return (STRING_HANDLE)my_gballoc_malloc(1); } -static STRING_HANDLE my_Base64_Encode_Bytes(const unsigned char* source, size_t size) +static STRING_HANDLE my_Azure_Base64_Encode_Bytes(const unsigned char* source, size_t size) { (void)source; (void)size; @@ -276,7 +278,7 @@ static char* my_Base32_Encode_Bytes(const unsigned char* source, size_t size) return result; } -static BUFFER_HANDLE my_Base64_Decoder(const char* source) +static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); @@ -374,8 +376,8 @@ BEGIN_TEST_SUITE(prov_auth_client_ut) REGISTER_GLOBAL_MOCK_HOOK(secure_device_sign_data, my_secure_device_sign_data); REGISTER_GLOBAL_MOCK_FAIL_RETURN(secure_device_sign_data, __LINE__); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encoder, my_Base64_Encoder); - REGISTER_GLOBAL_MOCK_RETURN(Base64_Encoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode, my_Base64_Encode); + REGISTER_GLOBAL_MOCK_RETURN(Azure_Base64_Encode, NULL); REGISTER_GLOBAL_MOCK_RETURN(BUFFER_create, TEST_BUFFER_VALUE); REGISTER_GLOBAL_MOCK_FAIL_RETURN(BUFFER_create, NULL); @@ -394,12 +396,12 @@ BEGIN_TEST_SUITE(prov_auth_client_ut) REGISTER_GLOBAL_MOCK_HOOK(mallocAndStrcpy_s, my_mallocAndStrcpy_s); REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, __LINE__); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encode_Bytes, my_Base64_Encode_Bytes); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode_Bytes, my_Azure_Base64_Encode_Bytes); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); REGISTER_GLOBAL_MOCK_HOOK(Base32_Encode_Bytes, my_Base32_Encode_Bytes); REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base32_Encode_Bytes, NULL); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); REGISTER_GLOBAL_MOCK_HOOK(STRING_construct, my_STRING_construct); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_construct, NULL); @@ -460,7 +462,7 @@ BEGIN_TEST_SUITE(prov_auth_client_ut) if (use_key) { STRICT_EXPECTED_CALL(secure_device_get_symm_key(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(BUFFER_new()); STRICT_EXPECTED_CALL(BUFFER_length(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(BUFFER_u_char(IGNORED_PTR_ARG)); @@ -483,7 +485,7 @@ BEGIN_TEST_SUITE(prov_auth_client_ut) STRICT_EXPECTED_CALL(size_tToString(IGNORED_PTR_ARG, IGNORED_NUM_ARG, IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); setup_sign_sas_data(use_key); - STRICT_EXPECTED_CALL(Base64_Encode_Bytes(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes(IGNORED_PTR_ARG, IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(URL_Encode(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)); @@ -1291,6 +1293,78 @@ BEGIN_TEST_SUITE(prov_auth_client_ut) prov_auth_destroy(sec_handle); } + TEST_FUNCTION(prov_auth_set_registration_id_handle_NULL_fail) + { + //arrange + + //act + int result = prov_auth_set_registration_id(NULL, TEST_REGISTRATION_ID); + + //assert + ASSERT_ARE_NOT_EQUAL(int, 0, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + } + + TEST_FUNCTION(prov_auth_set_registration_id_registration_id_NULL_fail) + { + PROV_AUTH_HANDLE sec_handle = prov_auth_create(); + umock_c_reset_all_calls(); + + //arrange + + //act + int result = prov_auth_set_registration_id(sec_handle, NULL); + + //assert + ASSERT_ARE_NOT_EQUAL(int, 0, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + prov_auth_destroy(sec_handle); + } + + TEST_FUNCTION(prov_auth_set_registration_id_success) + { + PROV_AUTH_HANDLE sec_handle = prov_auth_create(); + umock_c_reset_all_calls(); + + //arrange + STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + //act + int result = prov_auth_set_registration_id(sec_handle, TEST_REGISTRATION_ID); + + //assert + ASSERT_ARE_EQUAL(int, 0, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + prov_auth_destroy(sec_handle); + } + + TEST_FUNCTION(prov_auth_set_registration_id_2_calls_success) + { + PROV_AUTH_HANDLE sec_handle = prov_auth_create(); + umock_c_reset_all_calls(); + + //arrange + STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); + + //act + int result = prov_auth_set_registration_id(sec_handle, TEST_REGISTRATION_ID); + ASSERT_ARE_EQUAL(int, 0, result); + result = prov_auth_set_registration_id(sec_handle, TEST_REGISTRATION_ID); + + //assert + ASSERT_ARE_NOT_EQUAL(int, 0, result); + ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); + + //cleanup + prov_auth_destroy(sec_handle); + } + TEST_FUNCTION(prov_auth_get_certificate_succeed) { STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); diff --git a/provisioning_client/tests/prov_device_client_ll_ut/prov_device_client_ll_ut.c b/provisioning_client/tests/prov_device_client_ll_ut/prov_device_client_ll_ut.c index 0348148861..d4f11582fa 100644 --- a/provisioning_client/tests/prov_device_client_ll_ut/prov_device_client_ll_ut.c +++ b/provisioning_client/tests/prov_device_client_ll_ut/prov_device_client_ll_ut.c @@ -32,7 +32,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/sastoken.h" #include "azure_c_shared_utility/crt_abstractions.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/shared_util_options.h" #include "azure_c_shared_utility/agenttime.h" #include "azure_c_shared_utility/urlencode.h" @@ -351,13 +351,13 @@ static int my_mallocAndStrcpy_s(char** destination, const char* source) return 0; } -static STRING_HANDLE my_Base64_Encode_Bytes(const unsigned char* source, size_t size) +static STRING_HANDLE my_Azure_Base64_Encode_Bytes(const unsigned char* source, size_t size) { (void)source;(void)size; return (STRING_HANDLE)my_gballoc_malloc(1); } -static BUFFER_HANDLE my_Base64_Decoder(const char* source) +static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); @@ -484,10 +484,10 @@ BEGIN_TEST_SUITE(prov_device_client_ll_ut) REGISTER_GLOBAL_MOCK_HOOK(mallocAndStrcpy_s, my_mallocAndStrcpy_s); REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, __LINE__); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encode_Bytes, my_Base64_Encode_Bytes); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode_Bytes, my_Azure_Base64_Encode_Bytes); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); } TEST_SUITE_CLEANUP(suite_cleanup) @@ -629,7 +629,7 @@ BEGIN_TEST_SUITE(prov_device_client_ll_ut) STRICT_EXPECTED_CALL(json_object_get_value(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(json_value_get_string(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)); setup_retrieve_json_item_mocks(TEST_STRING_VALUE); STRICT_EXPECTED_CALL(json_value_free(IGNORED_PTR_ARG)); } @@ -693,7 +693,7 @@ BEGIN_TEST_SUITE(prov_device_client_ll_ut) STRICT_EXPECTED_CALL(json_object_get_object(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(json_object_get_value(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(json_value_get_string(IGNORED_PTR_ARG)).SetReturn(PROV_ASSIGNED_STATUS); - STRICT_EXPECTED_CALL(Base64_Decoder(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Decode(IGNORED_PTR_ARG)); setup_retrieve_json_item_mocks(TEST_STRING_VALUE); setup_retrieve_json_item_mocks(TEST_STRING_VALUE); diff --git a/provisioning_client/tests/prov_sasl_tpm_ut/prov_sasl_tpm_ut.c b/provisioning_client/tests/prov_sasl_tpm_ut/prov_sasl_tpm_ut.c index 74d44120f2..7f47179cfc 100644 --- a/provisioning_client/tests/prov_sasl_tpm_ut/prov_sasl_tpm_ut.c +++ b/provisioning_client/tests/prov_sasl_tpm_ut/prov_sasl_tpm_ut.c @@ -34,7 +34,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/buffer_.h" #include "azure_uamqp_c/sasl_mechanism.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" MOCKABLE_FUNCTION(, char*, on_challenge_callback, BUFFER_HANDLE, data, void*, user_ctx); @@ -95,7 +95,7 @@ static void my_STRING_delete(STRING_HANDLE handle) my_gballoc_free(handle); } -static BUFFER_HANDLE my_Base64_Decoder(const char* source) +static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); @@ -172,8 +172,8 @@ TEST_SUITE_INITIALIZE(suite_init) REGISTER_GLOBAL_MOCK_HOOK(on_challenge_callback, my_on_challenge_callback); REGISTER_GLOBAL_MOCK_FAIL_RETURN(on_challenge_callback, NULL); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); REGISTER_GLOBAL_MOCK_HOOK(STRING_new, my_STRING_new); REGISTER_GLOBAL_MOCK_FAIL_RETURN(STRING_new, NULL); diff --git a/provisioning_client/tests/prov_transport_amqp_client_ut/prov_transport_amqp_client_ut.c b/provisioning_client/tests/prov_transport_amqp_client_ut/prov_transport_amqp_client_ut.c index 79764f2a48..e9631c2438 100644 --- a/provisioning_client/tests/prov_transport_amqp_client_ut/prov_transport_amqp_client_ut.c +++ b/provisioning_client/tests/prov_transport_amqp_client_ut/prov_transport_amqp_client_ut.c @@ -240,7 +240,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(saslclientio_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); @@ -266,7 +265,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); //act dps_io_info = g_transport_io(TEST_URI_VALUE, NULL, NULL); @@ -296,22 +294,14 @@ BEGIN_TEST_SUITE(prov_transport_amqp_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(saslclientio_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); - size_t calls_cannot_fail[] = { 3 }; - umock_c_negative_tests_snapshot(); size_t count = umock_c_negative_tests_call_count(); for (size_t index = 0; index < count; index++) { - if (should_skip_index(index, calls_cannot_fail, sizeof(calls_cannot_fail) / sizeof(calls_cannot_fail[0])) != 0) - { - continue; - } - umock_c_negative_tests_reset(); umock_c_negative_tests_fail_call(index); @@ -343,7 +333,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(saslclientio_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); proxy_info.host_address = TEST_HOST_ADDRESS_VALUE; diff --git a/provisioning_client/tests/prov_transport_amqp_common_ut/prov_transport_amqp_common_ut.c b/provisioning_client/tests/prov_transport_amqp_common_ut/prov_transport_amqp_common_ut.c index 6eac6a8d9c..389ec07c67 100644 --- a/provisioning_client/tests/prov_transport_amqp_common_ut/prov_transport_amqp_common_ut.c +++ b/provisioning_client/tests/prov_transport_amqp_common_ut/prov_transport_amqp_common_ut.c @@ -46,7 +46,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/buffer_.h" #include "azure_uamqp_c/message_sender.h" diff --git a/provisioning_client/tests/prov_transport_amqp_ws_client_ut/prov_transport_amqp_ws_client_ut.c b/provisioning_client/tests/prov_transport_amqp_ws_client_ut/prov_transport_amqp_ws_client_ut.c index 7476e30b7d..d896e48a62 100644 --- a/provisioning_client/tests/prov_transport_amqp_ws_client_ut/prov_transport_amqp_ws_client_ut.c +++ b/provisioning_client/tests/prov_transport_amqp_ws_client_ut/prov_transport_amqp_ws_client_ut.c @@ -246,9 +246,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_ws_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif STRICT_EXPECTED_CALL(saslclientio_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); @@ -275,9 +272,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_ws_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif //act dps_io_info = g_transport_io(TEST_URI_VALUE, NULL, NULL); @@ -306,9 +300,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_ws_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif STRICT_EXPECTED_CALL(saslclientio_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); @@ -356,9 +347,6 @@ BEGIN_TEST_SUITE(prov_transport_amqp_ws_client_ut) STRICT_EXPECTED_CALL(http_proxy_io_get_interface_description()); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif STRICT_EXPECTED_CALL(saslclientio_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); proxy_info.host_address = TEST_HOST_ADDRESS_VALUE; diff --git a/provisioning_client/tests/prov_transport_http_client_ut/prov_transport_http_client_ut.c b/provisioning_client/tests/prov_transport_http_client_ut/prov_transport_http_client_ut.c index 4968a1fa78..d7144d99b8 100644 --- a/provisioning_client/tests/prov_transport_http_client_ut/prov_transport_http_client_ut.c +++ b/provisioning_client/tests/prov_transport_http_client_ut/prov_transport_http_client_ut.c @@ -38,7 +38,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/urlencode.h" #include "azure_c_shared_utility/platform.h" @@ -226,13 +226,13 @@ static void my_HTTPHeaders_Free(HTTP_HEADERS_HANDLE handle) my_gballoc_free(handle); } -static STRING_HANDLE my_Base64_Encoder(const BUFFER_HANDLE source) +static STRING_HANDLE my_Base64_Encode(const BUFFER_HANDLE source) { (void)source; return (STRING_HANDLE)my_gballoc_malloc(1); } -static BUFFER_HANDLE my_Base64_Decoder(const char* source) +static BUFFER_HANDLE my_Azure_Base64_Decode(const char* source) { (void)source; return (BUFFER_HANDLE)my_gballoc_malloc(1); @@ -374,8 +374,8 @@ BEGIN_TEST_SUITE(prov_transport_http_client_ut) REGISTER_GLOBAL_MOCK_HOOK(mallocAndStrcpy_s, my_mallocAndStrcpy_s); REGISTER_GLOBAL_MOCK_FAIL_RETURN(mallocAndStrcpy_s, __LINE__); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Encoder, my_Base64_Encoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Encode, my_Base64_Encode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode, NULL); REGISTER_GLOBAL_MOCK_HOOK(URL_EncodeString, my_URL_EncodeString); REGISTER_GLOBAL_MOCK_FAIL_RETURN(URL_EncodeString, NULL); REGISTER_GLOBAL_MOCK_RETURN(STRING_c_str, TEST_STRING_VALUE); @@ -391,8 +391,8 @@ BEGIN_TEST_SUITE(prov_transport_http_client_ut) REGISTER_GLOBAL_MOCK_HOOK(BUFFER_clone, my_BUFFER_clone); REGISTER_GLOBAL_MOCK_FAIL_RETURN(BUFFER_clone, NULL); - REGISTER_GLOBAL_MOCK_HOOK(Base64_Decoder, my_Base64_Decoder); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Decoder, NULL); + REGISTER_GLOBAL_MOCK_HOOK(Azure_Base64_Decode, my_Azure_Base64_Decode); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Decode, NULL); REGISTER_GLOBAL_MOCK_HOOK(BUFFER_delete, my_BUFFER_delete); REGISTER_GLOBAL_MOCK_RETURN(platform_get_default_tlsio, TEST_INTERFACE_DESC); @@ -519,8 +519,8 @@ BEGIN_TEST_SUITE(prov_transport_http_client_ut) STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(Base64_Encoder(IGNORED_PTR_ARG)); - STRICT_EXPECTED_CALL(Base64_Encoder(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode(IGNORED_PTR_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode(IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_length(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(STRING_length(IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(gballoc_malloc(IGNORED_NUM_ARG)); diff --git a/provisioning_client/tests/prov_transport_mqtt_client_ut/prov_transport_mqtt_client_ut.c b/provisioning_client/tests/prov_transport_mqtt_client_ut/prov_transport_mqtt_client_ut.c index c14bcc1d6e..1c08ba3e82 100644 --- a/provisioning_client/tests/prov_transport_mqtt_client_ut/prov_transport_mqtt_client_ut.c +++ b/provisioning_client/tests/prov_transport_mqtt_client_ut/prov_transport_mqtt_client_ut.c @@ -221,9 +221,6 @@ BEGIN_TEST_SUITE(prov_transport_mqtt_client_ut) //arrange STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif //act dps_io_info = g_transport_io(TEST_URI_VALUE, NULL); @@ -244,9 +241,6 @@ BEGIN_TEST_SUITE(prov_transport_mqtt_client_ut) //arrange STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif //act dps_io_info = g_transport_io(TEST_URI_VALUE, NULL); @@ -308,9 +302,6 @@ BEGIN_TEST_SUITE(prov_transport_mqtt_client_ut) STRICT_EXPECTED_CALL(http_proxy_io_get_interface_description()); STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif proxy_info.host_address = TEST_HOST_ADDRESS_VALUE; proxy_info.username = TEST_PRIVATE_KEY_VALUE; proxy_info.password = TEST_HOST_ADDRESS_VALUE; diff --git a/provisioning_client/tests/prov_transport_mqtt_common_ut/prov_transport_mqtt_common_ut.c b/provisioning_client/tests/prov_transport_mqtt_common_ut/prov_transport_mqtt_common_ut.c index bf0d368a69..9b6c4059d5 100644 --- a/provisioning_client/tests/prov_transport_mqtt_common_ut/prov_transport_mqtt_common_ut.c +++ b/provisioning_client/tests/prov_transport_mqtt_common_ut/prov_transport_mqtt_common_ut.c @@ -43,7 +43,7 @@ static void my_gballoc_free(void* ptr) #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/umock_c_prod.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/buffer_.h" #include "azure_c_shared_utility/umock_c_prod.h" diff --git a/provisioning_client/tests/prov_transport_mqtt_ws_client_ut/prov_transport_mqtt_ws_client_ut.c b/provisioning_client/tests/prov_transport_mqtt_ws_client_ut/prov_transport_mqtt_ws_client_ut.c index 125cad861b..e6a9104a03 100644 --- a/provisioning_client/tests/prov_transport_mqtt_ws_client_ut/prov_transport_mqtt_ws_client_ut.c +++ b/provisioning_client/tests/prov_transport_mqtt_ws_client_ut/prov_transport_mqtt_ws_client_ut.c @@ -226,9 +226,6 @@ BEGIN_TEST_SUITE(prov_transport_mqtt_ws_client_ut) STRICT_EXPECTED_CALL(wsio_get_interface_description()); STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif //act dps_io_info = g_transport_io(TEST_URI_VALUE, NULL); @@ -251,9 +248,6 @@ BEGIN_TEST_SUITE(prov_transport_mqtt_ws_client_ut) STRICT_EXPECTED_CALL(wsio_get_interface_description()); STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif //act dps_io_info = g_transport_io(TEST_URI_VALUE, NULL); @@ -317,9 +311,7 @@ BEGIN_TEST_SUITE(prov_transport_mqtt_ws_client_ut) STRICT_EXPECTED_CALL(platform_get_default_tlsio()); STRICT_EXPECTED_CALL(http_proxy_io_get_interface_description()); STRICT_EXPECTED_CALL(xio_create(TEST_INTERFACE_DESC, IGNORED_PTR_ARG)); -#ifdef USE_OPENSSL - STRICT_EXPECTED_CALL(xio_setoption(IGNORED_PTR_ARG, IGNORED_PTR_ARG, IGNORED_PTR_ARG)); -#endif + proxy_info.host_address = TEST_HOST_ADDRESS_VALUE; proxy_info.username = TEST_PRIVATE_KEY_VALUE; proxy_info.password = TEST_HOST_ADDRESS_VALUE; diff --git a/provisioning_client/tools/symm_key_provision/symm_key_provision.c b/provisioning_client/tools/symm_key_provision/symm_key_provision.c index 53cb1d0309..add210cdc6 100644 --- a/provisioning_client/tools/symm_key_provision/symm_key_provision.c +++ b/provisioning_client/tools/symm_key_provision/symm_key_provision.c @@ -10,7 +10,7 @@ #include "azure_c_shared_utility/uuid.h" #include "azure_c_shared_utility/sha.h" #include "azure_c_shared_utility/hmacsha256.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" typedef struct REGISTRATION_INFO_TAG { @@ -82,7 +82,7 @@ static int construct_individual_enrollment(void) UUID_T uuid; if (UUID_generate(&uuid) == 0) { - STRING_HANDLE device_key = Base64_Encode_Bytes(uuid, 16); + STRING_HANDLE device_key = Azure_Base64_Encode_Bytes(uuid, 16); if (device_key == NULL) { (void)printf("Failure generating key info\r\n"); @@ -123,7 +123,7 @@ static int construct_group_enrollment(void) { BUFFER_HANDLE decode_key; BUFFER_HANDLE hash; - if ((decode_key = Base64_Decoder(group_key)) == NULL) + if ((decode_key = Azure_Base64_Decode(group_key)) == NULL) { (void)printf("Failure decoding group key\r\n"); result = __LINE__; @@ -144,7 +144,7 @@ static int construct_group_enrollment(void) } else { - device_key = Base64_Encoder(hash); + device_key = Azure_Base64_Encode(hash); (void)printf("Symmetric Key: %s\r\n", STRING_c_str(device_key)); STRING_delete(device_key); result = 0; diff --git a/provisioning_client/tools/tpm_device_provision/tpm_device_provision.c b/provisioning_client/tools/tpm_device_provision/tpm_device_provision.c index 0aad78b0a0..9d46a6050e 100644 --- a/provisioning_client/tools/tpm_device_provision/tpm_device_provision.c +++ b/provisioning_client/tools/tpm_device_provision/tpm_device_provision.c @@ -10,7 +10,7 @@ #include "azure_c_shared_utility/strings.h" #include "azure_c_shared_utility/platform.h" #include "azure_c_shared_utility/sha.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_prov_client/prov_security_factory.h" #include "azure_prov_client/internal/prov_auth_client.h" @@ -79,7 +79,7 @@ int main() else { STRING_HANDLE encoded_ek; - if ((encoded_ek = Base64_Encoder(reg_info.endorsement_key)) == NULL) + if ((encoded_ek = Azure_Base64_Encode(reg_info.endorsement_key)) == NULL) { (void)printf("Failure base64 encoding ek"); result = __LINE__; diff --git a/provisioning_service_client/src/provisioning_sc_x509_attestation.c b/provisioning_service_client/src/provisioning_sc_x509_attestation.c index 8d17430ea2..298ca20998 100644 --- a/provisioning_service_client/src/provisioning_sc_x509_attestation.c +++ b/provisioning_service_client/src/provisioning_sc_x509_attestation.c @@ -7,7 +7,7 @@ #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/crt_abstractions.h" #include "azure_c_shared_utility/strings.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "prov_service_client/provisioning_sc_x509_attestation.h" #include "prov_service_client/provisioning_sc_json_const.h" @@ -63,7 +63,7 @@ static int convert_cert_to_b64(const char* cert_in, char** cert_b64_out) if (cert_in != NULL) { STRING_HANDLE cert_b64; - if ((cert_b64 = Base64_Encode_Bytes((const unsigned char*)cert_in, strlen(cert_in))) == NULL) + if ((cert_b64 = Azure_Base64_Encode_Bytes((const unsigned char*)cert_in, strlen(cert_in))) == NULL) { LogError("Could not convert certificate to Base64"); ret = __FAILURE__; diff --git a/provisioning_service_client/tests/prov_sc_x509_attestation_ut/prov_sc_x509_attestation_ut.c b/provisioning_service_client/tests/prov_sc_x509_attestation_ut/prov_sc_x509_attestation_ut.c index 73cde7bbdc..e143e673a0 100644 --- a/provisioning_service_client/tests/prov_sc_x509_attestation_ut/prov_sc_x509_attestation_ut.c +++ b/provisioning_service_client/tests/prov_sc_x509_attestation_ut/prov_sc_x509_attestation_ut.c @@ -29,7 +29,7 @@ void real_free(void* ptr) #define ENABLE_MOCKS #include "azure_c_shared_utility/gballoc.h" #include "azure_c_shared_utility/crt_abstractions.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/strings.h" #include "parson.h" @@ -136,8 +136,8 @@ static void register_global_mocks() REGISTER_GLOBAL_MOCK_FAIL_RETURN(json_object_set_number, JSONFailure); //base64 - REGISTER_GLOBAL_MOCK_RETURN(Base64_Encode_Bytes, TEST_STRING_HANDLE); - REGISTER_GLOBAL_MOCK_FAIL_RETURN(Base64_Encode_Bytes, NULL); + REGISTER_GLOBAL_MOCK_RETURN(Azure_Base64_Encode_Bytes, TEST_STRING_HANDLE); + REGISTER_GLOBAL_MOCK_FAIL_RETURN(Azure_Base64_Encode_Bytes, NULL); //string REGISTER_GLOBAL_MOCK_RETURN(STRING_c_str, DUMMY_STRING_64); @@ -293,7 +293,7 @@ static void expected_calls_x509Certificates_create(const char* primary_cert, con static void expected_calls_convert_cert_to_b64(const char* in, const char* out) { - STRICT_EXPECTED_CALL(Base64_Encode_Bytes((const unsigned char*)in, IGNORED_NUM_ARG)); + STRICT_EXPECTED_CALL(Azure_Base64_Encode_Bytes((const unsigned char*)in, IGNORED_NUM_ARG)); STRICT_EXPECTED_CALL(STRING_c_str(IGNORED_PTR_ARG)).SetReturn(out); STRICT_EXPECTED_CALL(mallocAndStrcpy_s(IGNORED_PTR_ARG, IGNORED_PTR_ARG)); STRICT_EXPECTED_CALL(STRING_delete(IGNORED_PTR_ARG)); diff --git a/readme.md b/readme.md index 44e893c9d6..8570e1d1b2 100644 --- a/readme.md +++ b/readme.md @@ -222,9 +222,8 @@ Below is a table showing the mapping of the LTS branches to the packages release | Package | Github Branch | LTS Status | LTS Start Date | Maintenance End Date | Removed Date | | :-----------: | :-----------: | :--------: | :------------: | :------------------: | :----------: | +| Vcpkg: 1.2.14-1
Xenial: 0.2.0.0-16xenial
Trusty: 0.2.0-16trusty
Bionic: 0.2.0.0-9bionic
| lts_01_2019 | Active | 2019-01-31 | 2020-01-31 | 2020-01-31 | | Nuget: 1.2.10
Xenial: 0.2.0.0-12xenial
Trusty: 0.2.0-12trusty
Bionic: 0.2.0.0-5bionic
| lts_10_2018 | Active | 2018-10-03 | 2019-10-03 | 2019-10-03 | -| Nuget: 1.1.33
Xenial: 0.1.0.0-35xenial
Trusty: 0.1.0-37trusty
| lts_01_2018 | Active | 2018-01-01 | 2018-12-31 | 2018-04-31 | - * 1 All scheduled dates are subject to change by the Azure IoT SDK team. diff --git a/samples/dockerbuilds/MIPS32/Dockerfile b/samples/dockerbuilds/MIPS32/Dockerfile new file mode 100644 index 0000000000..27cdcc8663 --- /dev/null +++ b/samples/dockerbuilds/MIPS32/Dockerfile @@ -0,0 +1,98 @@ +FROM ubuntu:latest + +# Run commands that require root authority +RUN apt-get update && apt-get -y upgrade +RUN apt-get install -y cmake git wget nano + +RUN useradd -d /home/builder -ms /bin/bash -G sudo -p builder builder + +# Switch to new user +USER builder +WORKDIR /home/builder + +# Download all required files +RUN mkdir MIPSBuild +WORKDIR MIPSBuild + +# Cross compile toolchain +RUN wget https://downloads.openwrt.org/barrier_breaker/14.07/ramips/mt7620n/OpenWrt-Toolchain-ramips-for-mipsel_24kec%2bdsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 +RUN tar -xvf OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2 + +# Azure IoT SDK for C +RUN git clone --recursive https://github.com/azure/azure-iot-sdk-c.git + +# OpenSSL +RUN wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz +RUN tar -xvf openssl-1.0.2o.tar.gz + +# Curl +RUN wget http://curl.haxx.se/download/curl-7.60.0.tar.gz +RUN tar -xvf curl-7.60.0.tar.gz + +# Linux utilities for libuuid +RUN wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.32/util-linux-2.32-rc2.tar.gz +RUN tar -xvf util-linux-2.32-rc2.tar.gz + +# Set up environment variables in preperation for the builds to follow +ENV WORK_ROOT=/home/builder/MIPSBuild +ENV TOOLCHAIN_ROOT=${WORK_ROOT}/OpenWrt-Toolchain-ramips-for-mipsel_24kec+dsp-gcc-4.8-linaro_uClibc-0.9.33.2 +ENV TOOLCHAIN_SYSROOT=${TOOLCHAIN_ROOT}/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2 +ENV TOOLCHAIN_EXES=${TOOLCHAIN_SYSROOT}/bin +ENV TOOLCHAIN_NAME=mipsel-openwrt-linux-uclibc +ENV AR=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-ar +ENV AS=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-as +ENV CC=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-gcc +ENV LD=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-ld +ENV NM=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-nm +ENV RANLIB=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-ranlib + +ENV LDFLAGS="-L${TOOLCHAIN_SYSROOT}/usr/lib" +ENV LIBS="-lssl -lcrypto -ldl -lpthread" +ENV TOOLCHAIN_PREFIX=${TOOLCHAIN_SYSROOT}/usr +ENV STAGING_DIR=${TOOLCHAIN_SYSROOT} + +# Build OpenSSL +WORKDIR openssl-1.0.2o +RUN ./Configure linux-generic32 shared --prefix=${TOOLCHAIN_PREFIX} --openssldir=${TOOLCHAIN_PREFIX} +RUN make +RUN make install +WORKDIR .. + +# Build curl +WORKDIR curl-7.60.0 +RUN ./configure --with-sysroot=${TOOLCHAIN_SYSROOT} --prefix=${TOOLCHAIN_PREFIX} --target=${TOOLCHAIN_NAME} --with-ssl --with-zlib --host=${TOOLCHAIN_NAME} --build=x86_64-pc-linux-uclibc +RUN make +RUN make install +WORKDIR .. + +# Build uuid +WORKDIR util-linux-2.32-rc2 +RUN ./configure --prefix=${TOOLCHAIN_PREFIX} --with-sysroot=${TOOLCHAIN_SYSROOT} --target=${TOOLCHAIN_NAME} --host=${TOOLCHAIN_NAME} --disable-all-programs --disable-bash-completion --enable-libuuid +RUN make +RUN make install +WORKDIR .. + +WORKDIR azure-iot-sdk-c +RUN mkdir cmake +WORKDIR cmake + +# Create a toolchain file on the fly +RUN echo "SET(CMAKE_SYSTEM_NAME Linux) # this one is important" > toolchain.cmake +RUN echo "SET(CMAKE_SYSTEM_VERSION 1) # this one not so much" >> toolchain.cmake +RUN echo "SET(CMAKE_SYSROOT ${TOOLCHAIN_SYSROOT})" >> toolchain.cmake +RUN echo "SET(CMAKE_C_COMPILER ${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-gcc)" >> toolchain.cmake +RUN echo "SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-g++)" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH $ENV{TOOLCHAIN_SYSROOT})" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> toolchain.cmake +RUN echo "SET(set_trusted_cert_in_samples true CACHE BOOL \"Force use of TrustedCerts option\" FORCE)" >> toolchain.cmake + +RUN cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake -DCMAKE_INSTALL_PREFIX=${TOOLCHAIN_PREFIX} .. +RUN make +RUN make install + +WORKDIR ../.. + +CMD ["/bin/bash"] + diff --git a/samples/dockerbuilds/MIPS32/Dockerfile_adjunct b/samples/dockerbuilds/MIPS32/Dockerfile_adjunct new file mode 100644 index 0000000000..bd278b4be8 --- /dev/null +++ b/samples/dockerbuilds/MIPS32/Dockerfile_adjunct @@ -0,0 +1,24 @@ +FROM mipsiotbuild:latest + +USER builder +WORKDIR /home/builder + +# Copy a directory from the host containing the files to build setting ownership at the same time +ADD --chown=builder:builder myapp myapp + +# Sanity check +RUN ls -al myapp + +# Switch to application directory +WORKDIR myapp + +# Create and switch to cmake directory +RUN mkdir cmake +WORKDIR cmake + +# Generate the makefiles with the same toolchain file and build +RUN cmake -DCMAKE_TOOLCHAIN_FILE=${WORK_ROOT}/azure-iot-sdk-c/cmake/toolchain.cmake .. +RUN make + +# There should be an executable called myapp +RUN ls -al myapp diff --git a/samples/dockerbuilds/README.md b/samples/dockerbuilds/README.md new file mode 100644 index 0000000000..8f9d4c1a4f --- /dev/null +++ b/samples/dockerbuilds/README.md @@ -0,0 +1,2 @@ +# Docker Build Samples +This directory contains sample Docker files to cross compile the Azure IoT SDK for Raspbian and MIPS32 OpenWRT targets. For more information see [here](https://github.com/Azure/azure-iot-sdk-c/blob/master/doc/Docker_SDK_Cross_Compile.md). \ No newline at end of file diff --git a/samples/dockerbuilds/RaspberryPi/Dockerfile b/samples/dockerbuilds/RaspberryPi/Dockerfile new file mode 100644 index 0000000000..732711ff0f --- /dev/null +++ b/samples/dockerbuilds/RaspberryPi/Dockerfile @@ -0,0 +1,111 @@ +# Start with the latest version of the Debian Docker container +FROM debian:stretch + +RUN ls -la + +# Fetch and install all outstanding updates +RUN apt-get update && apt-get -y upgrade + +# Install wget git cmake xz-utils +RUN apt-get install -y wget git cmake xz-utils + +# Add a non-root user +RUN useradd -d /home/builder -ms /bin/bash -G sudo -p builder builder + +# Switch to new user +USER builder +WORKDIR /home/builder +#WORKDIR /root + +# Don't use RPiTools because gcc is old, use linaro's toolchain +#RUN mkdir RPiTools +#WORKDIR RPiTools +#RUN git clone https://github.com/raspberrypi/tools.git + +RUN mkdir RPiBuild +ENV WORK_ROOT=/home/builder/RPiBuild +WORKDIR ${WORK_ROOT} + +RUN wget https://releases.linaro.org/components/toolchain/binaries/latest-7/arm-linux-gnueabihf/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz +RUN tar -xvf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf.tar.xz + +# Set up environment variables for builds +ENV TOOLCHAIN_ROOT=${WORK_ROOT}/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf +ENV TOOLCHAIN_SYSROOT=${TOOLCHAIN_ROOT} +ENV TOOLCHAIN_EXES=${TOOLCHAIN_SYSROOT}/bin +ENV TOOLCHAIN_NAME=arm-linux-gnueabihf +ENV TOOLCHAIN_PREFIX=${TOOLCHAIN_SYSROOT}/usr + +ENV AR=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-ar +ENV AS=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-as +ENV CC=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-gcc +ENV LD=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-ld +ENV NM=${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-nm + +ENV LDFLAGS="-L${TOOLCHAIN_SYSROOT}/usr/lib" +ENV LIBS="-lssl -lcrypto -ldl -lpthread" +ENV TOOLCHAIN_PREFIX=${TOOLCHAIN_SYSROOT}/usr +ENV STAGING_DIR=${TOOLCHAIN_SYSROOT} + +# Download OpenSSL source and expand it +RUN wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz +RUN tar -xvf openssl-1.1.0f.tar.gz + +# Build OpenSSL +WORKDIR openssl-1.1.0f +RUN ./Configure linux-generic32 shared --prefix=${TOOLCHAIN_PREFIX} --openssldir=${TOOLCHAIN_PREFIX} +RUN make +RUN make install +WORKDIR .. + +# Download cURL source and expand it +RUN wget http://curl.haxx.se/download/curl-7.60.0.tar.gz +RUN tar -xvf curl-7.60.0.tar.gz + +# Build cURL +# we need to set the path for openssl with --with-ssl=... +WORKDIR curl-7.60.0 +RUN ./configure --with-sysroot=${TOOLCHAIN_SYSROOT} --prefix=${TOOLCHAIN_PREFIX} --target=${TOOLCHAIN_NAME} --with-ssl=${TOOLCHAIN_PREFIX} --with-zlib --host=${TOOLCHAIN_NAME} --build=x86_64-linux-gnu +RUN make +RUN make install +WORKDIR .. + +# Download the Linux utilities for libuuid and expand it +RUN wget https://mirrors.edge.kernel.org/pub/linux/utils/util-linux/v2.32/util-linux-2.32-rc2.tar.gz +RUN tar -xvf util-linux-2.32-rc2.tar.gz + +# Build uuid +WORKDIR util-linux-2.32-rc2 +RUN ./configure --prefix=${TOOLCHAIN_PREFIX} --with-sysroot=${TOOLCHAIN_SYSROOT} --target=${TOOLCHAIN_NAME} --host=${TOOLCHAIN_NAME} --disable-all-programs --disable-bash-completion --enable-libuuid +RUN make +RUN make install +WORKDIR .. + +# clone azure +RUN git clone --recursive https://github.com/Azure/azure-iot-sdk-c.git +WORKDIR azure-iot-sdk-c + +# Create a working directory for the cmake operations +RUN mkdir cmake +WORKDIR cmake + +# Create a cmake toolchain file on the fly +RUN echo "SET(CMAKE_SYSTEM_NAME Linux) # this one is important" > toolchain.cmake +RUN echo "SET(CMAKE_SYSTEM_VERSION 1) # this one not so much" >> toolchain.cmake + +RUN echo "SET(CMAKE_C_COMPILER ${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-gcc)" >> toolchain.cmake +RUN echo "SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_EXES}/${TOOLCHAIN_NAME}-g++)" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_SYSROOT})" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> toolchain.cmake +RUN echo "SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> toolchain.cmake + +# Build the SDK. This will use the OpenSSL, cURL and uuid binaries that we built before +RUN cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake -Duse_prov_client:BOOL=OFF -DCMAKE_INSTALL_PREFIX=${TOOLCHAIN_PREFIX} .. +RUN make -j 2 +RUN make install +# or RUN cmake --build . + +WORKDIR ../.. + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/samples/dockerbuilds/RaspberryPi/Dockerfile_adjunct b/samples/dockerbuilds/RaspberryPi/Dockerfile_adjunct new file mode 100644 index 0000000000..5e212f8a31 --- /dev/null +++ b/samples/dockerbuilds/RaspberryPi/Dockerfile_adjunct @@ -0,0 +1,24 @@ +FROM rpiiotbuild:latest + +USER builder +WORKDIR /home/builder + +# Copy a directory from the host containing the files to build setting ownership at the same time +ADD --chown=builder:builder myapp myapp + +# Sanity check +RUN ls -al myapp + +# Switch to application directory +WORKDIR myapp + +# Create and switch to cmake directory +RUN mkdir cmake +WORKDIR cmake + +# Generate the makefiles with the same toolchain file and build +RUN cmake -DCMAKE_TOOLCHAIN_FILE=${WORK_ROOT}/azure-iot-sdk-c/cmake/toolchain.cmake .. +RUN make + +# There should be an executable called myapp +RUN ls -al myapp diff --git a/samples/dockerbuilds/myapp/CMakeLists.txt b/samples/dockerbuilds/myapp/CMakeLists.txt new file mode 100644 index 0000000000..d985f36702 --- /dev/null +++ b/samples/dockerbuilds/myapp/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 2.8.11) +project(myapp_project) + +# The demonstration uses C99 but it could just as easily be a C++ application +set (CMAKE_C_FLAGS "--std=c99 ${CMAKE_C_FLAGS}") + +# Assume we will use the built in trusted certificates. +# Many embedded devices will need this. +option(use_sample_trusted_cert "Set flag in samples to use SDK's built-in CA as TrustedCerts" ON) + +set(iothub_c_files + iothub_cross_compile_simple_sample.c +) + +# Conditionally use the SDK trusted certs in the samples (is set to true in cmake toolchain file) +if(${use_sample_trusted_cert}) + add_definitions(-DSET_TRUSTED_CERT_IN_SAMPLES) + include_directories($ENV{WORK_ROOT}/azure-iot-sdk-c/certs) + set(iothub_c_files + ${iothub_c_files} + $ENV{WORK_ROOT}/azure-iot-sdk-c/certs/certs.c) +endif() + +# Set up the include and library paths +include_directories($ENV{TOOLCHAIN_PREFIX}/include/) +include_directories($ENV{TOOLCHAIN_PREFIX}/include/azureiot) +link_directories($ENV{TOOLCHAIN_PREFIX}/lib) + +add_executable(myapp ${iothub_c_files}) + +# Redundant in this case but shows how to rename your output executable +set_target_properties(myapp PROPERTIES OUTPUT_NAME "myapp") + +# List the libraries required by the link step +target_link_libraries(myapp iothub_client_mqtt_transport iothub_client umqtt aziotsharedutil parson pthread curl ssl crypto m ) \ No newline at end of file diff --git a/samples/dockerbuilds/myapp/Dockerfile_adjunct b/samples/dockerbuilds/myapp/Dockerfile_adjunct new file mode 100644 index 0000000000..1c5bb5c1e0 --- /dev/null +++ b/samples/dockerbuilds/myapp/Dockerfile_adjunct @@ -0,0 +1,28 @@ +# This is a sample - there are working versions specifically for Raspberry Pi and MIPS32 + +# This file could be appended to the Dockerfile or could be set up to use the image created by +# the build step by including: + +# FROM :latest +# USER builder +# WORKDIR /home/builder + +# Copy a directory from the host containing the files to build setting ownership at the same time +ADD --chown=builder:builder myapp ${WORK_ROOT}/myapp + +# Sanity check +RUN ls -al myapp + +# Switch to application directory +WORKDIR myapp + +# Create and switch to cmake directory +RUN mkdir cmake +WORKDIR cmake + +# Generate the makefiles with the same toolchain file and build +RUN cmake -DCMAKE_TOOLCHAIN_FILE=${WORK_ROOT}/azure-iot-sdk-c/cmake/toolchain.cmake .. +RUN make + +# There should be an executable called myapp +RUN ls -al myapp diff --git a/samples/dockerbuilds/myapp/iothub_cross_compile_simple_sample.c b/samples/dockerbuilds/myapp/iothub_cross_compile_simple_sample.c new file mode 100644 index 0000000000..e3654a3dae --- /dev/null +++ b/samples/dockerbuilds/myapp/iothub_cross_compile_simple_sample.c @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +// CAVEAT: This sample is to demonstrate azure IoT client concepts only and is not a guide design principles or style +// Checking of return codes and error values shall be omitted for brevity. Please practice sound engineering practices +// when writing production code. + +// CAVEAT #2: This is a very minimal sample used to demonstrate how one can build one's own application in a cross compile +// environment using Docker. + +#include +#include +#include + +#include "iothub.h" +#include "iothub_device_client.h" +#include "iothub_client_options.h" +#include "iothub_message.h" +#include "azure_c_shared_utility/threadapi.h" +#include "azure_c_shared_utility/crt_abstractions.h" +#include "azure_c_shared_utility/platform.h" +#include "azure_c_shared_utility/shared_util_options.h" +#include "iothubtransportmqtt.h" + +/* This sample uses the convenience APIs of iothub_client for example purposes. */ + +#ifdef SET_TRUSTED_CERT_IN_SAMPLES +#include "certs.h" +#endif // SET_TRUSTED_CERT_IN_SAMPLES + +/* Paste in your device connection string */ +static const char* connectionString = "[device connection string]"; + +#define MESSAGE_COUNT 5 +int g_interval = 10000; // 10 sec send interval initially +static size_t g_message_count_send_confirmations = 0; + +static void send_confirm_callback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) +{ + (void)userContextCallback; + // When a message is sent this callback will get envoked + g_message_count_send_confirmations++; + (void)printf("Confirmation callback received for message %lu with result %s\r\n", (unsigned long)g_message_count_send_confirmations, ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result)); +} + +int main(void) +{ + IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = MQTT_Protocol; + + IOTHUB_MESSAGE_HANDLE message_handle; + float telemetry_temperature; + float telemetry_humidity; + const char* telemetry_scale = "Celcius"; + char telemetry_msg_buffer[80]; + + int messagecount = 0; + + printf("\r\nThis sample will send messages continuously and accept C2D messages.\r\nPress Ctrl+C to terminate the sample.\r\n\r\n"); + + IOTHUB_DEVICE_CLIENT_HANDLE device_handle; + + // Used to initialize IoTHub SDK subsystem + (void)IoTHub_Init(); + + (void)printf("Creating IoTHub handle\r\n"); + // Create the iothub handle here + device_handle = IoTHubDeviceClient_CreateFromConnectionString(connectionString, protocol); + if (device_handle == NULL) + { + (void)printf("Failure creating Iothub device. Hint: Check you connection string.\r\n"); + } + else + { +#ifdef SET_TRUSTED_CERT_IN_SAMPLES + // Setting the Trusted Certificate. This is only necessary on system with without + // built in certificate stores. + (void)IoTHubDeviceClient_SetOption(device_handle, OPTION_TRUSTED_CERT, certificates); +#endif // SET_TRUSTED_CERT_IN_SAMPLES + + int i = MESSAGE_COUNT; + + while(i--) + { + // Construct the iothub message + telemetry_temperature = 20.0f + ((float)rand() / RAND_MAX) * 15.0f; + telemetry_humidity = 60.0f + ((float)rand() / RAND_MAX) * 20.0f; + + sprintf(telemetry_msg_buffer, "{\"temperature\":%.3f,\"humidity\":%.3f,\"scale\":\"%s\"}", + telemetry_temperature, telemetry_humidity, telemetry_scale); + + message_handle = IoTHubMessage_CreateFromString(telemetry_msg_buffer); + + (void)printf("\r\nSending message %d to IoTHub\r\nMessage: %s\r\n", (int)(messagecount + 1), telemetry_msg_buffer); + IoTHubDeviceClient_SendEventAsync(device_handle, message_handle, send_confirm_callback, NULL); + + // The message is copied to the sdk so the we can destroy it + IoTHubMessage_Destroy(message_handle); + messagecount = messagecount + 1; + + ThreadAPI_Sleep(g_interval); + } + + // Clean up the iothub sdk handle + IoTHubDeviceClient_Destroy(device_handle); + } + // Free all the sdk subsystem + IoTHub_Deinit(); + + return 0; +} diff --git a/testtools/iothub_test/src/iothub_account.c b/testtools/iothub_test/src/iothub_account.c index dfc3c2f10c..6980c9dcc1 100755 --- a/testtools/iothub_test/src/iothub_account.c +++ b/testtools/iothub_test/src/iothub_account.c @@ -18,13 +18,12 @@ #include "iothub_account.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" +#include "azure_c_shared_utility/azure_base64.h" #include "azure_c_shared_utility/hmacsha256.h" #include "azure_c_shared_utility/xlogging.h" #include "azure_c_shared_utility/sastoken.h" #include "azure_c_shared_utility/httpapiexsas.h" -#include "azure_c_shared_utility/base64.h" #include "azure_c_shared_utility/uniqueid.h" #include "iothub_service_client_auth.h" @@ -617,7 +616,7 @@ static int provisionModule(IOTHUB_ACCOUNT_INFO* accountInfo, IOTHUB_PROVISIONED_ static char* convert_base64_to_string(const char* base64_cert) { char* result; - BUFFER_HANDLE raw_cert = Base64_Decoder(base64_cert); + BUFFER_HANDLE raw_cert = Azure_Base64_Decode(base64_cert); if (raw_cert == NULL) { LogError("Failure decoding base64 encoded cert.\r\n"); diff --git a/tools/CACertificates/certGen.sh b/tools/CACertificates/certGen.sh index 7401298345..8ff27cd1ed 100644 --- a/tools/CACertificates/certGen.sh +++ b/tools/CACertificates/certGen.sh @@ -28,6 +28,15 @@ intermediate_ca_password="1234" root_ca_prefix="azure-iot-test-only.root.ca" intermediate_ca_prefix="azure-iot-test-only.intermediate" +function makeCNsubject() +{ + local result="/CN=${1}" + case $OSTYPE in + msys|win32) result="/${result}" + esac + echo "$result" +} + function warn_certs_not_for_production() { tput smso @@ -64,7 +73,7 @@ function generate_root_ca() -config ${openssl_root_config_file} \ ${password_cmd} \ -key ${root_ca_dir}/private/${root_ca_prefix}.key.pem \ - -subj "/CN=${common_name}" \ + -subj "$(makeCNsubject "${common_name}")" \ -days ${days_till_expire} \ -sha256 \ -extensions v3_ca \ @@ -115,7 +124,7 @@ function generate_intermediate_ca() openssl req -new -sha256 \ ${password_cmd} \ -config ${openssl_intermediate_config_file} \ - -subj "/CN=${common_name}" \ + -subj "$(makeCNsubject "${common_name}")" \ -key ${intermediate_ca_dir}/private/${intermediate_ca_prefix}.key.pem \ -out ${intermediate_ca_dir}/csr/${intermediate_ca_prefix}.csr.pem [ $? -eq 0 ] || exit $? @@ -197,7 +206,7 @@ function generate_device_certificate_common() echo "----------------------------------------" openssl req -config ${openssl_config_file} \ -key ${certificate_dir}/private/${device_prefix}.key.pem \ - -subj "/CN=${common_name}" \ + -subj "$(makeCNsubject "${common_name}")" \ -new -sha256 -out ${certificate_dir}/csr/${device_prefix}.csr.pem [ $? -eq 0 ] || exit $? diff --git a/uamqp b/uamqp index 195f2480f3..13f009ddd5 160000 --- a/uamqp +++ b/uamqp @@ -1 +1 @@ -Subproject commit 195f2480f31e0a9492e3ff3a7a1eed4a69205ddd +Subproject commit 13f009ddd50a2837f651b0237de17db5f24c3af9 diff --git a/umqtt b/umqtt index f68e8d535d..6cd0cdeba6 160000 --- a/umqtt +++ b/umqtt @@ -1 +1 @@ -Subproject commit f68e8d535d18028e3e6ed4d806ce8994037a49fa +Subproject commit 6cd0cdeba607ed8de2e129e3451ef956f8ddf383 diff --git a/version.txt b/version.txt index 67eb68059b..589268e6fe 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.12 \ No newline at end of file +1.3.0 \ No newline at end of file