mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-01 13:10:43 +00:00
Merge pull request #3214 from cesanta/tests
introduce local MQTT server, fix container calling, fill prerequisites
This commit is contained in:
9 files changed
+146
-64
No files matched your search
@@ -33,11 +33,11 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CC: ${{ matrix.cc }}
|
CC: ${{ matrix.cc }}
|
||||||
SSL: ${{ matrix.ssl }}
|
SSL: ${{ matrix.ssl }}
|
||||||
TFLAGS: ${{ matrix.select }}
|
TFLAGS: ${{ matrix.select }} -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: sudo apt -y update ; sudo apt -y install libmbedtls-dev libwolfssl-dev && make -C test ${{ matrix.target }}
|
- run: sudo apt -y update ; sudo apt -y install libmbedtls-dev libwolfssl-dev && test/setup_mqtt_server.sh && make -C test ${{ matrix.target }}
|
||||||
mip:
|
mip:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -50,6 +50,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CC: ${{ matrix.cc }}
|
CC: ${{ matrix.cc }}
|
||||||
SSL: ${{ matrix.ssl }}
|
SSL: ${{ matrix.ssl }}
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
@@ -73,10 +74,12 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
ssl: ["", BUILTIN]
|
ssl: ["", BUILTIN]
|
||||||
name: S390 SSL=${{ matrix.ssl }}
|
name: S390 SSL=${{ matrix.ssl }}
|
||||||
|
env:
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test s390 SSL=${{ matrix.ssl }} MULTIREC=NO
|
- run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && ./test/setup_mqtt_server.sh && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test s390 SSL=${{ matrix.ssl }} MULTIREC=NO
|
||||||
armhf:
|
armhf:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -84,10 +87,12 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
ssl: ["", BUILTIN]
|
ssl: ["", BUILTIN]
|
||||||
name: ArmHF SSL=${{ matrix.ssl }}
|
name: ArmHF SSL=${{ matrix.ssl }}
|
||||||
|
env:
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test armhf SSL=${{ matrix.ssl }} MULTIREC=NO
|
- run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && ./test/setup_mqtt_server.sh && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test armhf SSL=${{ matrix.ssl }} MULTIREC=NO
|
||||||
unamalgamated-mg_prefix:
|
unamalgamated-mg_prefix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -107,11 +112,13 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
ssl: ["", BUILTIN, MBEDTLS, OPENSSL, WOLFSSL]
|
ssl: ["", BUILTIN, MBEDTLS, OPENSSL, WOLFSSL]
|
||||||
name: Valgrind SSL=${{ matrix.ssl }}
|
name: Valgrind SSL=${{ matrix.ssl }}
|
||||||
|
env:
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: sudo apt -y update ; sudo apt -y install libmbedtls-dev libwolfssl-dev valgrind
|
- run: sudo apt -y update ; sudo apt -y install libmbedtls-dev libwolfssl-dev valgrind
|
||||||
- run: make -C test valgrind SSL=${{ matrix.ssl }}
|
- run: ./test/setup_mqtt_server.sh && make -C test valgrind SSL=${{ matrix.ssl }}
|
||||||
macos:
|
macos:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -129,12 +136,13 @@ jobs:
|
|||||||
name: macos SSL=${{ matrix.ssl }} TFLAGS=${{ matrix.select }}
|
name: macos SSL=${{ matrix.ssl }} TFLAGS=${{ matrix.select }}
|
||||||
env:
|
env:
|
||||||
SSL: ${{ matrix.ssl }}
|
SSL: ${{ matrix.ssl }}
|
||||||
TFLAGS: ${{ matrix.select }} -Wno-sign-conversion # Workaround for MbedTLS 3.5.0
|
TFLAGS: ${{ matrix.select }} -DMQTT_LOCALHOST -Wno-sign-conversion # Workaround for MbedTLS 3.5.0
|
||||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: brew install mbedtls wolfssl # jq openssl already pre-installed
|
- run: brew install mbedtls wolfssl mosquitto # jq openssl already pre-installed
|
||||||
|
- run: /opt/homebrew/opt/mosquitto/sbin/mosquitto -c /Users/runner/work/mongoose/mongoose/test/mosquitto.conf.macos &
|
||||||
- run: make -C test test ASAN_OPTIONS= MBEDTLS=$(echo $(brew --cellar)/mbedtls*/*) OPENSSL=$(echo $(brew --cellar)/openssl*/*) WOLFSSL=$(echo $(brew --cellar)/wolfssl*/*)
|
- run: make -C test test ASAN_OPTIONS= MBEDTLS=$(echo $(brew --cellar)/mbedtls*/*) OPENSSL=$(echo $(brew --cellar)/openssl*/*) WOLFSSL=$(echo $(brew --cellar)/wolfssl*/*)
|
||||||
windows:
|
windows:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -151,11 +159,11 @@ jobs:
|
|||||||
name: windows ${{ matrix.target }} SSL=${{ matrix.ssl }} TFLAGS=${{ matrix.select }}
|
name: windows ${{ matrix.target }} SSL=${{ matrix.ssl }} TFLAGS=${{ matrix.select }}
|
||||||
env:
|
env:
|
||||||
SSL: ${{ matrix.ssl }}
|
SSL: ${{ matrix.ssl }}
|
||||||
TFLAGS: ${{ matrix.select }}
|
TFLAGS: ${{ matrix.select }} -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: make -C test ${{ matrix.target }}
|
- run: ./test/setup_mqtt_server.sh && make -C test ${{ matrix.target }}
|
||||||
arm:
|
arm:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -186,7 +194,7 @@ jobs:
|
|||||||
name: tutorials ${{ matrix.ssl }}
|
name: tutorials ${{ matrix.ssl }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: sudo apt -y install libpcap-dev
|
- run: sudo apt -y install libpcap-dev && npm -g i tailwindcss tailwindcss-font-inter
|
||||||
- run: make -C test tutorials CFLAGS_EXTRA="${{ matrix.ssl }}"
|
- run: make -C test tutorials CFLAGS_EXTRA="${{ matrix.ssl }}"
|
||||||
- run: make -C test clean_tutorials
|
- run: make -C test clean_tutorials
|
||||||
tutorials_win:
|
tutorials_win:
|
||||||
|
|||||||
@@ -22,28 +22,33 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
CC: ${{ matrix.cc }}
|
CC: ${{ matrix.cc }}
|
||||||
SSL: ${{ matrix.ssl }}
|
SSL: ${{ matrix.ssl }}
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
||||||
- if: ${{ env.GO == 1 }}
|
- if: ${{ env.GO == 1 }}
|
||||||
run: make -C test ${{ matrix.target }}
|
run: if [ "${{ matrix.target }}" == "test" ]; then ./test/setup_mqtt_server.sh ; fi && make -C test ${{ matrix.target }}
|
||||||
s390:
|
s390:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
||||||
- if: ${{ env.GO == 1 }}
|
- if: ${{ env.GO == 1 }}
|
||||||
run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test s390
|
run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && ./test/setup_mqtt_server.sh && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test s390
|
||||||
armhf:
|
armhf:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
env:
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
||||||
- if: ${{ env.GO == 1 }}
|
- if: ${{ env.GO == 1 }}
|
||||||
run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test armhf
|
run: sudo apt -y update ; sudo apt -y install binfmt-support qemu-user-static && ./test/setup_mqtt_server.sh && docker run --rm --privileged multiarch/qemu-user-static --reset -p yes && make -C test armhf
|
||||||
unamalgamated-mg_prefix:
|
unamalgamated-mg_prefix:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -61,14 +66,17 @@ jobs:
|
|||||||
name: macos SSL=${{ matrix.ssl }}
|
name: macos SSL=${{ matrix.ssl }}
|
||||||
env:
|
env:
|
||||||
SSL: ${{ matrix.ssl }}
|
SSL: ${{ matrix.ssl }}
|
||||||
#TFLAGS: -DNO_SNTP_CHECK
|
TFLAGS: -DMQTT_LOCALHOST # -DNO_SNTP_CHECK
|
||||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
||||||
- if: ${{ env.GO == 1 }}
|
- if: ${{ env.GO == 1 }}
|
||||||
run: make -C test test ASAN_OPTIONS=
|
run: |
|
||||||
|
brew install mosquitto
|
||||||
|
/opt/homebrew/opt/mosquitto/sbin/mosquitto -c /Users/runner/work/mongoose/mongoose/test/mosquitto.conf.macos &
|
||||||
|
make -C test test ASAN_OPTIONS=
|
||||||
windows:
|
windows:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
@@ -76,12 +84,14 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
target: [vc98, vc22, mingw++]
|
target: [vc98, vc22, mingw++]
|
||||||
name: windows ${{ matrix.target }}
|
name: windows ${{ matrix.target }}
|
||||||
|
env:
|
||||||
|
TFLAGS: -DMQTT_LOCALHOST
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with: { fetch-depth: 2 }
|
with: { fetch-depth: 2 }
|
||||||
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
- run: if ./test/match_changed_files.sh '^test|^src/.*.[ch]' ; then echo GO=1 >> $GITHUB_ENV ; fi
|
||||||
- if: ${{ env.GO == 1 }}
|
- if: ${{ env.GO == 1 }}
|
||||||
run: make -C test ${{ matrix.target }}
|
run: ./test/setup_mqtt_server.sh && make -C test ${{ matrix.target }}
|
||||||
arm:
|
arm:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -97,6 +107,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- run: npm -g i tailwindcss tailwindcss-font-inter
|
||||||
- run: make -C test tutorials_essential
|
- run: make -C test tutorials_essential
|
||||||
- run: make -C test clean_tutorials_essential
|
- run: make -C test clean_tutorials_essential
|
||||||
tutorials_win:
|
tutorials_win:
|
||||||
@@ -117,6 +128,7 @@ jobs:
|
|||||||
env: { HOMEBREW_NO_AUTO_UPDATE: 1 }
|
env: { HOMEBREW_NO_AUTO_UPDATE: 1 }
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
- run: npm -g i tailwindcss tailwindcss-font-inter
|
||||||
- run: make -C test tutorials_mac
|
- run: make -C test tutorials_mac
|
||||||
- run: make -C test clean_tutorials_mac
|
- run: make -C test clean_tutorials_mac
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -9,7 +9,8 @@ CWD ?= $(realpath $(CURDIR))
|
|||||||
ROOT_DIR = $(realpath $(CWD)/..)
|
ROOT_DIR = $(realpath $(CWD)/..)
|
||||||
ENV ?= -e Tmp=. -e WINEDEBUG=-all
|
ENV ?= -e Tmp=. -e WINEDEBUG=-all
|
||||||
DOCKER_BIN ?= docker
|
DOCKER_BIN ?= docker
|
||||||
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --rm $(ENV) -v $(ROOT_DIR):$(ROOT_DIR) -w $(CWD)
|
# use net=host so all tests have the same network and can access localhost and ad hoc services
|
||||||
|
DOCKER ?= $(DOCKER_BIN) run --platform linux/amd64 --net=host --rm $(ENV) -v $(ROOT_DIR):$(ROOT_DIR) -w $(CWD)
|
||||||
VCFLAGS ?= /nologo /W3 /O2 /MD /I.
|
VCFLAGS ?= /nologo /W3 /O2 /MD /I.
|
||||||
IPV6 ?= 1
|
IPV6 ?= 1
|
||||||
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
|
ASAN ?= -fsanitize=address,undefined,alignment -fno-sanitize-recover=all -fno-omit-frame-pointer -fno-common
|
||||||
@@ -164,17 +165,18 @@ misra:
|
|||||||
cppcheck --addon=misra --clang -DMG_ENABLE_LINES=1 -DMG_ENABLE_SSI=1 mongoose.c >>/tmp/x 2>&1
|
cppcheck --addon=misra --clang -DMG_ENABLE_LINES=1 -DMG_ENABLE_SSI=1 mongoose.c >>/tmp/x 2>&1
|
||||||
less /tmp/x
|
less /tmp/x
|
||||||
|
|
||||||
|
# https://ddanilov.me/how-signals-are-handled-in-a-docker-container
|
||||||
armhf: ASAN=
|
armhf: ASAN=
|
||||||
armhf: IPV6=0
|
armhf: IPV6=0
|
||||||
armhf: CC = $(DOCKER) mdashnet/armhf cc
|
armhf: CC = $(DOCKER) mdashnet/armhf cc
|
||||||
armhf: RUN = $(DOCKER) mdashnet/armhf
|
armhf: RUN = $(DOCKER) --init mdashnet/armhf
|
||||||
armhf: test
|
armhf: test
|
||||||
|
|
||||||
s390: ASAN=
|
s390: ASAN=
|
||||||
s390: IPV6=0
|
s390: IPV6=0
|
||||||
s390: CFLAGS += -Wno-stringop-overflow
|
s390: CFLAGS += -Wno-stringop-overflow
|
||||||
s390: CC = $(DOCKER) mdashnet/s390 cc
|
s390: CC = $(DOCKER) mdashnet/s390 cc
|
||||||
s390: RUN = $(DOCKER) mdashnet/s390
|
s390: RUN = $(DOCKER) --init mdashnet/s390
|
||||||
s390: test
|
s390: test
|
||||||
|
|
||||||
arm: DEFS += -DMG_ENABLE_POSIX_FS=0 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_TCPIP_DRIVER_INIT=0 -DMG_ARCH=MG_ARCH_ARMGCC -DNO_SLEEP_ABORT
|
arm: DEFS += -DMG_ENABLE_POSIX_FS=0 -DMG_ENABLE_TCPIP=1 -DMG_ENABLE_TCPIP_DRIVER_INIT=0 -DMG_ARCH=MG_ARCH_ARMGCC -DNO_SLEEP_ABORT
|
||||||
|
|||||||
+21
-3
@@ -20,9 +20,13 @@
|
|||||||
|
|
||||||
#include "driver_mock.c"
|
#include "driver_mock.c"
|
||||||
|
|
||||||
#define MQTT_URL "mqtt://broker.hivemq.com:1883" // MQTT broker URL
|
#ifdef MQTT_LOCALHOST
|
||||||
|
#define MQTT_URL "mqtt://127.0.0.1:1883"
|
||||||
|
#else
|
||||||
|
#define MQTT_URL "mqtt://broker.hivemq.com:1883"
|
||||||
|
#endif
|
||||||
#if MG_TLS == MG_TLS_BUILTIN
|
#if MG_TLS == MG_TLS_BUILTIN
|
||||||
#define MQTTS_URL "mqtts://mongoose.ws:8883" // HiveMQ does not do TLS1.3
|
#define MQTTS_URL "mqtts://mongoose.ws:8883" // test requires TLS 1.3
|
||||||
#define MQTTS_CA mg_str(s_ca_cert)
|
#define MQTTS_CA mg_str(s_ca_cert)
|
||||||
static const char *s_ca_cert =
|
static const char *s_ca_cert =
|
||||||
"-----BEGIN CERTIFICATE-----\n"
|
"-----BEGIN CERTIFICATE-----\n"
|
||||||
@@ -57,8 +61,22 @@ static const char *s_ca_cert =
|
|||||||
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
|
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
|
||||||
"-----END CERTIFICATE-----\n";
|
"-----END CERTIFICATE-----\n";
|
||||||
#elif MG_TLS
|
#elif MG_TLS
|
||||||
#define MQTTS_URL "mqtts://broker.hivemq.com:8883" // MQTT broker URL
|
#ifdef MQTT_LOCALHOST
|
||||||
|
#define MQTTS_URL "mqtts://127.0.0.1:8883"
|
||||||
|
#define MQTTS_CA mg_str(s_ca_cert)
|
||||||
|
static const char *s_ca_cert =
|
||||||
|
"-----BEGIN CERTIFICATE-----\n"
|
||||||
|
"MIIBFTCBvAIJAMNTFtpfcq8NMAoGCCqGSM49BAMCMBMxETAPBgNVBAMMCE1vbmdv\n"
|
||||||
|
"b3NlMB4XDTI0MDUwNzE0MzczNloXDTM0MDUwNTE0MzczNlowEzERMA8GA1UEAwwI\n"
|
||||||
|
"TW9uZ29vc2UwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASuP+86T/rOWnGpEVhl\n"
|
||||||
|
"fxYZ+pjMbCmDZ+vdnP0rjoxudwRMRQCv5slRlDK7Lxue761sdvqxWr0Ma6TFGTNg\n"
|
||||||
|
"epsRMAoGCCqGSM49BAMCA0gAMEUCIQCwb2CxuAKm51s81S6BIoy1IcandXSohnqs\n"
|
||||||
|
"us64BAA7QgIgGGtUrpkgFSS0oPBlCUG6YPHFVw42vTfpTC0ySwAS0M4=\n"
|
||||||
|
"-----END CERTIFICATE-----\n";
|
||||||
|
#else
|
||||||
|
#define MQTTS_URL "mqtts://broker.hivemq.com:8883"
|
||||||
#define MQTTS_CA mg_unpacked("/data/ca.pem")
|
#define MQTTS_CA mg_unpacked("/data/ca.pem")
|
||||||
|
#endif // MQTT_LOCALHOST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char *host_ip;
|
static char *host_ip;
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
listener 8883 127.0.0.1
|
||||||
|
cafile /etc/mosquitto/certs/ca.crt
|
||||||
|
certfile /etc/mosquitto/certs/server.crt
|
||||||
|
keyfile /etc/mosquitto/certs/server.key
|
||||||
|
#
|
||||||
|
listener 1883 127.0.0.1
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
allow_anonymous true
|
||||||
|
listener 8883 127.0.0.1
|
||||||
|
cafile /Users/runner/work/mongoose/mongoose/test/certs/ca.crt
|
||||||
|
certfile /Users/runner/work/mongoose/mongoose/test/certs/server.crt
|
||||||
|
keyfile /Users/runner/work/mongoose/mongoose/test/certs/server.key
|
||||||
|
#
|
||||||
|
listener 1883 127.0.0.1
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
BRIDGE=mg_bridge0
|
BRIDGE=mg_bridge0
|
||||||
BRIDGE_BROADCAST=192.168.32.255
|
BRIDGE_BROADCAST=192.168.32.255
|
||||||
BRIDGE_IP=192.168.32.1
|
BRIDGE_IP=192.168.32.1
|
||||||
BRIDGE_IP_MASK=192.168.32.0/24
|
BRIDGE_NETWORK=192.168.32.0/24
|
||||||
BRIDGE_MASK=255.255.255.0
|
BRIDGE_MASK=255.255.255.0
|
||||||
PHY=eth0
|
// Host network is 'eth0'
|
||||||
TAP=tap0
|
TAP=tap0
|
||||||
|
|
||||||
# see our network configuration
|
# see our network configuration
|
||||||
@@ -33,16 +33,16 @@ sudo ip link set $TAP up
|
|||||||
echo
|
echo
|
||||||
|
|
||||||
echo "Network configuration script: NAT"
|
echo "Network configuration script: NAT"
|
||||||
sudo iptables -A FORWARD -d $BRIDGE_IP_MASK -o $BRIDGE -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
sudo iptables -A FORWARD -d $BRIDGE_NETWORK -o $BRIDGE -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
|
||||||
sudo iptables -A FORWARD -s $BRIDGE_IP_MASK -i $BRIDGE -j ACCEPT
|
sudo iptables -A FORWARD -s $BRIDGE_NETWORK -i $BRIDGE -j ACCEPT
|
||||||
sudo iptables -A FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT
|
sudo iptables -A FORWARD -i $BRIDGE -o $BRIDGE -j ACCEPT
|
||||||
sudo iptables -A FORWARD -o $BRIDGE -j REJECT --reject-with icmp-port-unreachable
|
sudo iptables -A FORWARD -o $BRIDGE -j REJECT --reject-with icmp-port-unreachable
|
||||||
sudo iptables -A FORWARD -i $BRIDGE -j REJECT --reject-with icmp-port-unreachable
|
sudo iptables -A FORWARD -i $BRIDGE -j REJECT --reject-with icmp-port-unreachable
|
||||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK -d 224.0.0.0/24 -j RETURN
|
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_NETWORK -d 224.0.0.0/24 -j RETURN
|
||||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK -d 255.255.255.255/32 -j RETURN
|
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_NETWORK -d 255.255.255.255/32 -j RETURN
|
||||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK ! -d $BRIDGE_IP_MASK -p tcp -j MASQUERADE --to-ports 1024-65535
|
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_NETWORK ! -d $BRIDGE_NETWORK -p tcp -j MASQUERADE --to-ports 1024-65535
|
||||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK ! -d $BRIDGE_IP_MASK -p udp -j MASQUERADE --to-ports 1024-65535
|
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_NETWORK ! -d $BRIDGE_NETWORK -p udp -j MASQUERADE --to-ports 1024-65535
|
||||||
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_IP_MASK ! -d $BRIDGE_IP_MASK -j MASQUERADE
|
sudo iptables -t nat -A POSTROUTING -s $BRIDGE_NETWORK ! -d $BRIDGE_NETWORK -j MASQUERADE
|
||||||
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
|
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
|
||||||
echo
|
echo
|
||||||
|
|
||||||
|
|||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
sudo apt-get -y install mosquitto
|
||||||
|
sudo cp test/mosquitto.conf /etc/mosquitto/conf.d/
|
||||||
|
sudo cp test/certs/ca.crt /etc/mosquitto/certs/
|
||||||
|
sudo cp test/certs/serverc.crt /etc/mosquitto/certs/
|
||||||
|
sudo cp test/certs/serverc.key /etc/mosquitto/certs/
|
||||||
|
sudo chmod a+w /var/log/mosquitto/*
|
||||||
|
sudo mosquitto -c /etc/mosquitto/mosquitto.conf &
|
||||||
+53
-33
@@ -375,9 +375,13 @@ static void test_sntp(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MQTT_URL "mqtt://broker.hivemq.com:1883" // MQTT broker URL
|
#ifdef MQTT_LOCALHOST
|
||||||
|
#define MQTT_URL "mqtt://127.0.0.1:1883"
|
||||||
|
#else
|
||||||
|
#define MQTT_URL "mqtt://broker.hivemq.com:1883"
|
||||||
|
#endif
|
||||||
#if MG_TLS == MG_TLS_BUILTIN
|
#if MG_TLS == MG_TLS_BUILTIN
|
||||||
#define MQTTS_URL "mqtts://mongoose.ws:8883" // HiveMQ does not do TLS1.3
|
#define MQTTS_URL "mqtts://mongoose.ws:8883" // test requires TLS 1.3
|
||||||
#define MQTTS_CA mg_str(s_ca_cert)
|
#define MQTTS_CA mg_str(s_ca_cert)
|
||||||
static const char *s_ca_cert =
|
static const char *s_ca_cert =
|
||||||
"-----BEGIN CERTIFICATE-----\n"
|
"-----BEGIN CERTIFICATE-----\n"
|
||||||
@@ -412,8 +416,22 @@ static const char *s_ca_cert =
|
|||||||
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
|
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n"
|
||||||
"-----END CERTIFICATE-----\n";
|
"-----END CERTIFICATE-----\n";
|
||||||
#elif MG_TLS
|
#elif MG_TLS
|
||||||
#define MQTTS_URL "mqtts://broker.hivemq.com:8883" // MQTT broker URL
|
#ifdef MQTT_LOCALHOST
|
||||||
|
#define MQTTS_URL "mqtts://127.0.0.1:8883"
|
||||||
|
#define MQTTS_CA mg_str(s_ca_cert)
|
||||||
|
static const char *s_ca_cert =
|
||||||
|
"-----BEGIN CERTIFICATE-----\n"
|
||||||
|
"MIIBFTCBvAIJAMNTFtpfcq8NMAoGCCqGSM49BAMCMBMxETAPBgNVBAMMCE1vbmdv\n"
|
||||||
|
"b3NlMB4XDTI0MDUwNzE0MzczNloXDTM0MDUwNTE0MzczNlowEzERMA8GA1UEAwwI\n"
|
||||||
|
"TW9uZ29vc2UwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAASuP+86T/rOWnGpEVhl\n"
|
||||||
|
"fxYZ+pjMbCmDZ+vdnP0rjoxudwRMRQCv5slRlDK7Lxue761sdvqxWr0Ma6TFGTNg\n"
|
||||||
|
"epsRMAoGCCqGSM49BAMCA0gAMEUCIQCwb2CxuAKm51s81S6BIoy1IcandXSohnqs\n"
|
||||||
|
"us64BAA7QgIgGGtUrpkgFSS0oPBlCUG6YPHFVw42vTfpTC0ySwAS0M4=\n"
|
||||||
|
"-----END CERTIFICATE-----\n";
|
||||||
|
#else
|
||||||
|
#define MQTTS_URL "mqtts://broker.hivemq.com:8883"
|
||||||
#define MQTTS_CA mg_unpacked("/data/ca.pem")
|
#define MQTTS_CA mg_unpacked("/data/ca.pem")
|
||||||
|
#endif // MQTT_LOCALHOST
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct mqtt_data {
|
struct mqtt_data {
|
||||||
@@ -438,8 +456,11 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
struct mg_tls_opts opts;
|
struct mg_tls_opts opts;
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
opts.ca = MQTTS_CA;
|
opts.ca = MQTTS_CA;
|
||||||
|
#if defined( MQTT_LOCALHOST) && MG_TLS != MG_TLS_BUILTIN
|
||||||
|
MG_ERROR(("Hostname not tested"));
|
||||||
|
#else
|
||||||
opts.name = mg_url_host(MQTTS_URL);
|
opts.name = mg_url_host(MQTTS_URL);
|
||||||
|
#endif
|
||||||
mg_tls_init(c, &opts);
|
mg_tls_init(c, &opts);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
@@ -468,35 +489,34 @@ static void mqtt_cb(struct mg_connection *c, int ev, void *ev_data) {
|
|||||||
mm->data.buf);
|
mm->data.buf);
|
||||||
|
|
||||||
if (mm->cmd == MQTT_CMD_PUBLISH && c->is_mqtt5) {
|
if (mm->cmd == MQTT_CMD_PUBLISH && c->is_mqtt5) {
|
||||||
size_t pos = 0;
|
size_t pos = 0, i = 0, j = 0;
|
||||||
struct mg_mqtt_prop prop;
|
struct mg_mqtt_prop prop;
|
||||||
|
|
||||||
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) > 0);
|
for (i = 0; i < 5 ; i++) {
|
||||||
ASSERT(prop.iv == 10 && prop.id == MQTT_PROP_MESSAGE_EXPIRY_INTERVAL);
|
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) > 0);
|
||||||
|
if (prop.id == MQTT_PROP_MESSAGE_EXPIRY_INTERVAL) {
|
||||||
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) > 0);
|
ASSERT(prop.iv == 10);
|
||||||
ASSERT(prop.id == MQTT_PROP_PAYLOAD_FORMAT_INDICATOR);
|
j += 1;
|
||||||
|
} else if (prop.id == MQTT_PROP_PAYLOAD_FORMAT_INDICATOR) {
|
||||||
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) > 0);
|
j += 2;
|
||||||
ASSERT(prop.id == MQTT_PROP_CONTENT_TYPE);
|
continue;
|
||||||
ASSERT(strncmp(prop.val.buf, "test_content_val_2", prop.val.len) == 0 &&
|
} else if (prop.id == MQTT_PROP_CONTENT_TYPE) {
|
||||||
prop.val.len == strlen("test_content_val_2"));
|
ASSERT(strncmp(prop.val.buf, "test_content_val_2", prop.val.len) == 0 && prop.val.len == strlen("test_content_val_2"));
|
||||||
|
j += 4;
|
||||||
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) > 0);
|
} else if (prop.id == MQTT_PROP_USER_PROPERTY) {
|
||||||
ASSERT(prop.id == MQTT_PROP_USER_PROPERTY);
|
if (strncmp(prop.key.buf, "test_key_1", prop.key.len) == 0 && prop.key.len == strlen("test_key_1")) {
|
||||||
ASSERT(strncmp(prop.key.buf, "test_key_1", prop.key.len) == 0 &&
|
ASSERT(strncmp(prop.val.buf, "test_value_1", prop.val.len) == 0 && prop.val.len == strlen("test_value_1"));
|
||||||
prop.key.len == strlen("test_key_1"));
|
j += 8;
|
||||||
ASSERT(strncmp(prop.val.buf, "test_value_1", prop.val.len) == 0 &&
|
} else if (strncmp(prop.key.buf, "test_key_2", prop.key.len) == 0 && prop.key.len == strlen("test_key_2")) {
|
||||||
prop.val.len == strlen("test_value_1"));
|
ASSERT(strncmp(prop.val.buf, "test_value_2", prop.val.len) == 0 && prop.val.len == strlen("test_value_2"));
|
||||||
|
j += 16;
|
||||||
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) > 0);
|
} else {
|
||||||
ASSERT(prop.id == MQTT_PROP_USER_PROPERTY);
|
ASSERT(0);
|
||||||
ASSERT(strncmp(prop.key.buf, "test_key_2", prop.key.len) == 0 &&
|
}
|
||||||
prop.key.len == strlen("test_key_2"));
|
}
|
||||||
ASSERT(strncmp(prop.val.buf, "test_value_2", prop.val.len) == 0 &&
|
}
|
||||||
prop.val.len == strlen("test_value_2"));
|
|
||||||
|
|
||||||
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) == 0);
|
ASSERT((pos = mg_mqtt_next_prop(mm, &prop, pos)) == 0);
|
||||||
|
ASSERT(j == 31);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(void) c;
|
(void) c;
|
||||||
@@ -527,7 +547,7 @@ static void test_mqtt_base(void) {
|
|||||||
struct mqtt_data test_data = {buf, buf, 10, 10, 0};
|
struct mqtt_data test_data = {buf, buf, 10, 10, 0};
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
struct mg_connection *c;
|
struct mg_connection *c;
|
||||||
const char *url = "mqtt://broker.hivemq.com:1883";
|
const char *url = MQTT_URL;
|
||||||
int i;
|
int i;
|
||||||
mg_mgr_init(&mgr);
|
mg_mgr_init(&mgr);
|
||||||
|
|
||||||
@@ -572,7 +592,7 @@ static void test_mqtt_basic(void) {
|
|||||||
#if MG_TLS
|
#if MG_TLS
|
||||||
const char *url = MQTTS_URL;
|
const char *url = MQTTS_URL;
|
||||||
#else
|
#else
|
||||||
const char *url = "mqtt://broker.hivemq.com:1883";
|
const char *url = MQTT_URL;
|
||||||
#endif
|
#endif
|
||||||
int i, retries;
|
int i, retries;
|
||||||
|
|
||||||
@@ -651,7 +671,7 @@ static void test_mqtt_ver(uint8_t mqtt_version) {
|
|||||||
struct mg_connection *c;
|
struct mg_connection *c;
|
||||||
struct mg_mqtt_opts opts;
|
struct mg_mqtt_opts opts;
|
||||||
struct mg_mqtt_prop properties[5];
|
struct mg_mqtt_prop properties[5];
|
||||||
const char *url = "mqtt://broker.hivemq.com:1883";
|
const char *url = MQTT_URL;
|
||||||
int i, retries;
|
int i, retries;
|
||||||
|
|
||||||
MG_DEBUG(("ver: %u", mqtt_version));
|
MG_DEBUG(("ver: %u", mqtt_version));
|
||||||
|
|||||||
Reference in new issue
Block a user