From 1fb0b8367a0560a1091f54104cea5a6885b1ebbf Mon Sep 17 00:00:00 2001 From: Steven Roebert Date: Mon, 13 Apr 2020 16:05:53 +0200 Subject: [PATCH] Updated unit tests --- .travis.yml | 11 ++-- .travis/certs/ca.crt | 20 +++++++ .travis/certs/ca.key | 28 ++++++++++ .travis/certs/ca.srl | 1 + .travis/certs/client.crt | 20 +++++++ .travis/certs/client.csr | 17 ++++++ .travis/certs/client.key | 28 ++++++++++ .travis/certs/generate.sh | 33 ++++++++++++ .travis/certs/server.crt | 37 +++++++------ .travis/certs/server.csr | 17 ++++++ .travis/certs/server.key | 52 +++++++++---------- .travis/generate.txt | 1 - .travis/mosquitto.conf | 14 +++-- Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift | 14 ++--- Tests/MQTTNIOTests/Core/TestUtils.swift | 6 +-- Tests/MQTTNIOTests/Tests/PublishTests.swift | 27 ++++++++-- 16 files changed, 255 insertions(+), 71 deletions(-) create mode 100644 .travis/certs/ca.crt create mode 100644 .travis/certs/ca.key create mode 100644 .travis/certs/ca.srl create mode 100644 .travis/certs/client.crt create mode 100644 .travis/certs/client.csr create mode 100644 .travis/certs/client.key create mode 100755 .travis/certs/generate.sh create mode 100644 .travis/certs/server.csr delete mode 100644 .travis/generate.txt diff --git a/.travis.yml b/.travis.yml index a74bf50..fdcc6c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,22 @@ +language: generic +dist: bionic +os: linux + branches: only: - master - develop - env: global: - CODECOV_ELIGIBLE=true - -matrix: +jobs: include: - os: linux dist: bionic - sudo: required - os: linux dist: xenial - sudo: required - os: osx osx_image: xcode11.4 - sudo: required before_install: - git clone https://github.com/IBM-Swift/Package-Builder.git diff --git a/.travis/certs/ca.crt b/.travis/certs/ca.crt new file mode 100644 index 0000000..32870df --- /dev/null +++ b/.travis/certs/ca.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDTjCCAjYCCQCj16WexG3HWDANBgkqhkiG9w0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+XXC1ULkrN8vFG6ZaLESE1By+SzvcEWGa3+e2lXdxQhv7pw== +-----END CERTIFICATE----- diff --git a/.travis/certs/ca.key b/.travis/certs/ca.key new file mode 100644 index 0000000..3c20066 --- /dev/null +++ b/.travis/certs/ca.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC9sdXLwJw0n99S +GYv+OGEnLDFn0h0hUOXn4Hv1pPBmJEEVU3QUFNFyM+F1f3z9STpE2hTm4Ut9xMS4 +6/f7dR2J9S8DFcOKxT0+9npJhpDXSwvqJYs1iaClApXBDxdJe9NxbaKQLXNyo8EO +E+/OX72sV5PFk1ZKNWbRTzTKSztS0aQmJAQX2R497iqTjsWqWzP3w4hbbuvrl31U +1hIjcKYoifdWvugcO6/Cdk1MmrF8HcMuw27Z5ybjnyQhaFiJc0KsWCf/ZFMNYwFY +ZMluWI20xFOjoeww1CI8b95bY/JU36h9YLcBT1Gy//IY4KFD77jl5qY/ydCROqdl +K7S96RrBAgMBAAECggEBAK6jPS/y6Bwunxtnd5GY+CBnOCjbsIPOhYp/CcAxlDyE +3gIzLWebbuOTzdotf7VzqBhhKeMQwT5NW8rfOxMeVA6BUkGl1Ls6MNN5eUWdhFUg +uxxaahnk1ad0hMgTC55USGphw8q2fVWqWn6KbjjxvZ4flmTL6yIwnbLPF8uxjTEF +Rc36e5yA/giLx6w6I/ymyMNaT9taUYqFJwKjtAj2+x4HP4SoEjIUOxJdhthN4O+X +lqLquNflmu7oKnVELx1aBNOFbmZyEgtcgjWwlG/H/SP6wL/BT0aJ7IoozKePpJoO +0XeGNcD+c9qyP0WswFCXNDSKhcyW9XxV2mIAU4L28e0CgYEA9brpaTyPkldoPVGd +oE/JVLie07aK1FmIfKuYtKn2ITXF5eGkGelqqHVITTFzqNKeJmbNJZuM05LOpu0G +3TiG0zdlZ+NppnkZGAG41XXAG5/TpG9OaitQXB4kgSdUbTgnRfN3RgqHTiGW9hLr +o40k3F6rZyO0zpaQM/cjfhrh2sMCgYEAxZ9lJZBVIbwTw6r7XcgyUpzT9xProvP4 +iKUnqeeYtBm4F5oHYbnl+s2qzoK4cIuOzSLbmmEfQ5Fcxef7t269CDbkxBKgLHGa +sgFLn8n0c18uE8GtLcg5XmToqABTIqakAxzbJCk3eSyYtr6I7T7e+ELsxoUDDAEK +pQW4QJozdCsCgYEAhiBr3yFLTJmhMDcoTqS+RBwxtWXiCV6FfWc8hwBudFohlwS+ +ydX6fdDmkhv4AaJU6KkcOPbau3Fakwq1wHJmRUvrcfVTaaaX596owPrwzSNEJnEK +4DCcQGvDiSuqjaMk7K2j4PtGN4NmHxLcw/z6rb6O2FFJE6pjM7omCWMq/HkCgYBq +Ca3/KuPTFxTPz8XSu2HtHANMNx8fr6LyxxNyQjeYo5g46cf+Mv5oxcRZzKBkmy2D +eqm0u1pIKg5KjsBs23mIl9PGNWxGjKqBytomIfoNkcuqhCiFQUMvGBwSUSJKnHmy +xd/8FjWSylAi9jeIfUysj1R27NYGseRhSaFk4JitQwKBgQCvDTNUjiD1oiyJ8c29 +sdlFxfbpng8GpYJF52292mMVuKtLD+JCJWXNGR8QUP13Scu14GyrqnovdJQq/vgJ +QA/93hHYGMBX1iuVImcCH0TFiY9m5EyyWjY87hx7frb3Dn0ZHV8Mro8FWUNZwEEJ +pJ/K3C6K2yKTkU9w8jZpO5RDbA== +-----END PRIVATE KEY----- diff --git a/.travis/certs/ca.srl b/.travis/certs/ca.srl new file mode 100644 index 0000000..09e85fa --- /dev/null +++ b/.travis/certs/ca.srl @@ -0,0 +1 @@ +AB64B2593168AD4A diff --git a/.travis/certs/client.crt b/.travis/certs/client.crt new file mode 100644 index 0000000..21125fd --- /dev/null +++ b/.travis/certs/client.crt @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDUjCCAjoCCQCrZLJZMWitSjANBgkqhkiG9w0BAQsFADBpMQswCQYDVQQGEwJO +TDESMBAGA1UECA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LhShdZCbzZ04= +-----END CERTIFICATE----- diff --git a/.travis/certs/client.csr b/.travis/certs/client.csr new file mode 100644 index 0000000..d62d69a --- /dev/null +++ b/.travis/certs/client.csr @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIICsjCCAZoCAQAwbTELMAkGA1UEBhMCTkwxEjAQBgNVBAgMCUFtc3RlcmRhbTES +MBAGA1UEBwwJQW1zdGVyZGFtMRAwDgYDVQQKDAdyb2ViZXJ0MQ8wDQYDVQQLDAZD +bGllbnQxEzARBgNVBAMMCnJvZWJlcnQubmwwggEiMA0GCSqGSIb3DQEBAQUAA4IB +DwAwggEKAoIBAQCuPxzAqMsogZruai/BXiV83xJplYJhMb+mPPCl5kZuKmOxcXb7 +cBEmFhSQMr/9v5QGg5KPFzrIcgcxtzGgPU5v+jCb2K1s8qzMSN7MPxVjaJkYPS7E +iIuu7vnJbcPGNxPFoA+es5HeSV9VTE7rdUZhLw3lvXxjJ9uxU+bW61c9ipSgO8sD +7lleqqCsyOQKtlC/1+48oATlORUK36EipnGWRjpGP//tCmlmsScIv6iuwImmg3fo +Wp+5jCPpY/1SfeqDgd81LzF6V1SUx/P1Za/AsJyTzSd49DcGbW+K10pWXCd+wNSk +HMPHQBQvF4D41ixDC6uPGejQuEfm6upAtxD1AgMBAAGgADANBgkqhkiG9w0BAQsF +AAOCAQEAHrp6J6uBXBs7HyhXISzG19CDqrjb8kfI5XgzcplWjdHNzQ2/bzEqFARl +a/f7h7Z7EFHR8gsoY1GExKHpb0KJdbnCGcSsdLuMmGWHZcaSuDZk5OWIBe4h7cdH +Bd9ou+909iNymqVBXodW16lYLa1//vR2m58WkZI4v6X1VdFgsfKzzyd/OIYKVGnV +bECja7GJzfj3qPL/NM2afq3VFvnya1BXMzNExNCFFhCidIZFqZqSBsp4uAxZs/sG +IAU+/OZXBeKnQh6Qj00ICso+v0Mhy6A8PC7f+5NQxE3V6wvR/hF24rCkx8tzEIsG +Vh3j8j6MwKsHohs77AavtLGEKtBE9w== +-----END CERTIFICATE REQUEST----- diff --git a/.travis/certs/client.key b/.travis/certs/client.key new file mode 100644 index 0000000..74678dd --- /dev/null +++ b/.travis/certs/client.key @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCuPxzAqMsogZru +ai/BXiV83xJplYJhMb+mPPCl5kZuKmOxcXb7cBEmFhSQMr/9v5QGg5KPFzrIcgcx +tzGgPU5v+jCb2K1s8qzMSN7MPxVjaJkYPS7EiIuu7vnJbcPGNxPFoA+es5HeSV9V +TE7rdUZhLw3lvXxjJ9uxU+bW61c9ipSgO8sD7lleqqCsyOQKtlC/1+48oATlORUK +36EipnGWRjpGP//tCmlmsScIv6iuwImmg3foWp+5jCPpY/1SfeqDgd81LzF6V1SU +x/P1Za/AsJyTzSd49DcGbW+K10pWXCd+wNSkHMPHQBQvF4D41ixDC6uPGejQuEfm +6upAtxD1AgMBAAECggEBAKy/OzUx4r/UxhHpylCNkuLakPmGVQ0g8hzQO9BtnJOp +iM6pa8lZUFcO+vH+rmLWJN3UYV9lK0z/52v9b8CqJvJS+w/23/CsIm4hLGkXfY/h +ai4ishP8P2d92rw9CyOfBQYfanzvEAVtfoslLPS4fr7olIGYuxHeuSpzwN5/0Szb +a8gjNzrHtUPCJFTVMEAIO2/ey1x2l2rRRJTez1/46q35IjRuhPMZFCrOjzYY+rHE +fFeiJgzbP+4zcdnhPn4eZs8e5SFgNVHjvfIk2XMVUqLGFLoqvAqjtWZDEi6XEgkP +M5YHOSF2iNpWqzn0IcLc0O6xgUWzlead67P3tq9nZF0CgYEA5XPkp4cv2PGiJJIu +9VS3sE6HfhWRMLgicOs0x+yyMUgTTnta6VSdQ9fzfXiKJOelkb0aMYJENf7r0LLX +yDo+HbDCg3wJfkLwldBg5OB8VfNHgbDFv1Ah/aS2O+UVT+lkgCMUuiFnEqEh/tLc +0QMjz3TCLYP+oJvIlXgeJsOE0kcCgYEAwmgUhZ2NuBkARfSKtidkiBWkmgPdesQL +8jQ+tiYQArPUnji77K+kLE6zGE4Y7h87mZDN6w0wm4y+CoNW/rJAl6NCN0Gtn3HS +KSmAmqr1kPKXJ6jfCy75AJ/sioIfWyiTAV1jELmAhula7p1lpbkwt+UaOyPDpuL0 +lNrdAIxchOMCgYAilmi2VCuDQVFWv+5yLtYNrpjACdI8DNWsPdhT9rsZsKqwXuni +WE3ohyn+FOiGDaEoqd/D7MYJeabka8EZPqZUZWu81Dq+HKsVejbQ6YH0ltqFkzcL +0rF9AZIyzyJ6TE1I/4DFWfmmlkGAnxqIKzf/srL+l3IPlcwTs+qfn0NrSwKBgQCn +9V4NlnJzZH488irJdz0+6Vv9iGtYfnpHtmWb30Sj4RRH4oJR2enAMfo/fHHDgQ5v +/ZA6jHm7WhxyXsjRYdW2bOFvdfn4MFE/KNEoT527ritzo02YjuuoY4Lso8FNc7+W +RUWqlGn7pS7fyvKf/GCf8Hr6L0sBK0HePT0FFT91uwKBgQCvAbzDCHtgE+VSSdy9 +gQdHtMnhc99+O2z0RStQQTHC5CaAeCcFfZa4jcZVjzNtlmE6u630Mv9Fk8HO0ds7 +j2gdgs9wrXxAXjz62W6EL2nkBy5BwnH3YoBjUyRNKD0SK/7XSozsngoLyUyd8NF3 +RZAqLCXpnubakrXT+I8DNoGWtg== +-----END PRIVATE KEY----- diff --git a/.travis/certs/generate.sh b/.travis/certs/generate.sh new file mode 100755 index 0000000..408fb67 --- /dev/null +++ b/.travis/certs/generate.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +IP="roebert.nl" +SUBJECT_CA="/C=NL/ST=Amsterdam/L=Amsterdam/O=roebert/OU=CA/CN=$IP" +SUBJECT_SERVER="/C=NL/ST=Amsterdam/L=Amsterdam/O=roebert/OU=Server/CN=$IP" +SUBJECT_CLIENT="/C=NL/ST=Amsterdam/L=Amsterdam/O=roebert/OU=Client/CN=$IP" + +function generate_CA () { + echo "$SUBJECT_CA" + openssl req -x509 -nodes -sha256 -newkey rsa:2048 -subj "$SUBJECT_CA" -days 365 -keyout ca.key -out ca.crt +} + +function generate_server () { + echo "$SUBJECT_SERVER" + openssl req -nodes -sha256 -new -subj "$SUBJECT_SERVER" -keyout server.key -out server.csr + openssl x509 -req -sha256 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 +} + +function generate_client () { + echo "$SUBJECT_CLIENT" + openssl req -new -nodes -sha256 -subj "$SUBJECT_CLIENT" -out client.csr -keyout client.key + openssl x509 -req -sha256 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 +} + +function copy_keys_to_broker () { + mv ca.crt certs/ + mv server.crt certs/ + mv server.key certs/ +} + +generate_CA +generate_server +generate_client diff --git a/.travis/certs/server.crt b/.travis/certs/server.crt index dac16e8..21ad331 100644 --- a/.travis/certs/server.crt +++ b/.travis/certs/server.crt @@ -1,21 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDXjCCAkYCCQD+8B0SyjMz+DANBgkqhkiG9w0BAQsFADBxMQswCQYDVQQGEwJO -TDESMBAGA1UEBwwJQW1zdGVyZGFtMRcwFQYDVQQKDA5TdGV2ZW4gUm9lYmVydDET -MBEGA1UEAwwKcm9lYmVydC5ubDEgMB4GCSqGSIb3DQEJARYRc3RldmVuQHJvZWJl -cnQubmwwHhcNMjAwNDEyMTEyNzMwWhcNMjEwNDEyMTEyNzMwWjBxMQswCQYDVQQG -EwJOTDESMBAGA1UEBwwJQW1zdGVyZGFtMRcwFQYDVQQKDA5TdGV2ZW4gUm9lYmVy -dDETMBEGA1UEAwwKcm9lYmVydC5ubDEgMB4GCSqGSIb3DQEJARYRc3RldmVuQHJv -ZWJlcnQubmwwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCeNjVvMMaG -N111PvDiO8hXi3ZRY1c9uOUKDSSuH2FNKP/5Epk3eNdGpjspB8TrHOn4a0z1Ker5 -GarKISPk+r/lXBeGFHtwffcckej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W5ddCKffp9+DgTswS5P +H2RmG4F7jEN+fAVsUUJhcuwxFUX64UKRX3HMMAGTrhPCZZxUmR/lrdlyZtgHjvMr ++aTmDJBS91wi6RVjFUdvPXeG40HMKNFq4qIQVVE/v+kVpO8UFNAhuek+WX42PgDs +1YiBdLNxIreGFKY+7g2VMt9AG8SHLypahXuYGC43gNvrBoaVJ4+AziLu9QHvwMP+ +o1s2ovmfFEjdK0kDy9Ii3S3tHYKiNnGN11jJh+oTvBBZhL0kB67wtfaq3NKSlZIt +ZciNZwy+joSKDPjOckuEYnUBTHD1q1ZuayBqxGIWxZS1Sn61nzsznPVubXuHAgMB +AAEwDQYJKoZIhvcNAQELBQADggEBAH3giPUKTepWZxEzMBs8Gv7KukQeByv6h73u +BFKTmLnDe5yt8uEdg5vkIGW6hOLMprBBAakeAjFn7/i+FW64qS0/a3J5xStYXEn7 +WUgYxSLC4Wxr5qflPPrZ0CcC62g6gcEYAy6Fd7Ega/CbZlB3ZFPbeJneVcSVvu8D +VI+mY+1K3R6Qjd0S5fz0TdXcyzM4cCPwai5vpXIa+neA88ZiHzvHR3fWKRjTX3L8 +xHDc3PmSYltpoQlXJ0B/0A0idOOnOvVo/wGMFTBBHYcRpQiZ7yS0QkN6A322aP4+ +78OPJmEb4+lOUstwvYBfzBfLhMVE+iVSlGDMR33YWFYv4uSrT3w= -----END CERTIFICATE----- diff --git a/.travis/certs/server.csr b/.travis/certs/server.csr new file mode 100644 index 0000000..5b1e8e1 --- /dev/null +++ b/.travis/certs/server.csr @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE REQUEST----- +MIICsjCCAZoCAQAwbTELMAkGA1UEBhMCTkwxEjAQBgNVBAgMCUFtc3RlcmRhbTES +MBAGA1UEBwwJQW1zdGVyZGFtMRAwDgYDVQQKDAdyb2ViZXJ0MQ8wDQYDVQQLDAZT +ZXJ2ZXIxEzARBgNVBAMMCnJvZWJlcnQubmwwggEiMA0GCSqGSIb3DQEBAQUAA4IB +DwAwggEKAoIBAQCwMWSXSW5ddCKffp9+DgTswS5PH2RmG4F7jEN+fAVsUUJhcuwx +FUX64UKRX3HMMAGTrhPCZZxUmR/lrdlyZtgHjvMr+aTmDJBS91wi6RVjFUdvPXeG +40HMKNFq4qIQVVE/v+kVpO8UFNAhuek+WX42PgDs1YiBdLNxIreGFKY+7g2VMt9A +G8SHLypahXuYGC43gNvrBoaVJ4+AziLu9QHvwMP+o1s2ovmfFEjdK0kDy9Ii3S3t +HYKiNnGN11jJh+oTvBBZhL0kB67wtfaq3NKSlZItZciNZwy+joSKDPjOckuEYnUB +THD1q1ZuayBqxGIWxZS1Sn61nzsznPVubXuHAgMBAAGgADANBgkqhkiG9w0BAQsF +AAOCAQEAoI+Uk+TD4voUtwJ62Oj7rBFWWfbXeLcgG38QqWgXBAv48lcpKOtbGIag +BFqNtjWExf1PquO3cZG9fDBdtP/phgHJ3Bo2awIVvRXdIHC+xHvSHk30DZbDhOLl +Pef+wCxTX4+kM2bUIfZXpXj+pcziW2Ec0JO7o1p37G64smDvzqWrOfnaXpPT8PxG +SJpRtQ/9H25ksdR4fLuFLZS/Nv5VlUdTcwcHLw9j7WFc4Ojq6xMHRKRyuYJzbcCV +772CC+qq8Vp0vX+mwvybE4Dt9HJ/lGhu+jlmZnqC5A6Xmd3vi/eTILfJB9PnDyd9 +nn664E0RTwvLaUYq4OpONVtEYYaXng== +-----END CERTIFICATE REQUEST----- diff --git a/.travis/certs/server.key b/.travis/certs/server.key index 107c232..4b23633 100644 --- a/.travis/certs/server.key +++ b/.travis/certs/server.key @@ -1,28 +1,28 @@ -----BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCeNjVvMMaGN111 -PvDiO8hXi3ZRY1c9uOUKDSSuH2FNKP/5Epk3eNdGpjspB8TrHOn4a0z1Ker5GarK -ISPk+r/lXBeGFHtwffcckejQqrh0CmKfUqUb43gX9RcNhU20hK8st6JXxy/ZLPJq -1kurI7ekM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Z8HqTBnvB8jR91uvq9o6wpDOoh +FP+nkdCd0GlYFvjE0sGpr2UogWU0lw3YLLJWUkYVEQKBgQDVzkXxR7ytUleV1KAp +ukPmfYgtICaHJHyJiROH9qzYsHW0r6nLstI9lr8fQ1Wt7UTdZIa7TIM6Gkl1cPR5 +JGbtwGL9UScfyS17vGCBq4bzXbvnOQXtSONaMI4LXUU0CyQ2yfxTUdLf7oA1Qn8X +PBPeMtsm9g47yFc8PXyAbnUcKwKBgQDS9t/npgpPceDp4XMUnS4RuXz8rNu3ZMLn +jwoh4N4PimbG1BJO/LksUqOAqMnUk4MD/JifvjDUQFZCi3wJZ6rY9St4nQBY0QB/ +G0mSKy5ySQpbhNIjs5yWkdbHs5v6L6ay2UuO/GwoL8rL/8mAKghT17eyIkezNMkt +t9M/suSEFQKBgDquIW4mVTdwqQ87SzYIpEgnXe+cqlZfAjsxPwYLAsd6LuQHbl+0 +1ZUHwa7P6T0SKNtmkr/nMQEKY+zysnZpMkLAkaqa0lUb/vq96fLM4/35VPASK3lD +jvqa5vFhiPPOtwK+jx1DENBbAh8cAAuddop+hL19vMxVoPOsoHYTWtr/AoGBANCs +9omzChvPb0SphyXq3DkYG3PsoGFlwA1AxisAvWbt5f/iokGTZq9bBvQrAYnOaBg3 +cdkBTleFVE36nzTGYI6+5MMnucIg6rbQDRQStpzBdwdT+HDsJ4YguC1NkooFPIVI +v56uPWX68ESdvXmTGi2lAcWodvfizOT2InWtxLCJAoGBAJ3Vb9ZMpawDZ2DdEyj1 +/e87Mp7WiVvVflQlgldY5XMnoCw4l/PbxCn51X9GQUTliIo1p+LCOQHilNAV/SoK +fa2Ibhup+ohtQwhhF7PNwyfT1RC5CB7pdd/oRLy9uhU5yc+pXUKXZ97fUqPUpr47 +77EFM3df7pnhwZmww9WNixA/ -----END PRIVATE KEY----- diff --git a/.travis/generate.txt b/.travis/generate.txt deleted file mode 100644 index 33b966f..0000000 --- a/.travis/generate.txt +++ /dev/null @@ -1 +0,0 @@ -openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt diff --git a/.travis/mosquitto.conf b/.travis/mosquitto.conf index 2eb7a1f..c4f4314 100644 --- a/.travis/mosquitto.conf +++ b/.travis/mosquitto.conf @@ -1,17 +1,21 @@ # Setup max_inflight_messages 20 max_queued_messages 1000 +allow_anonymous true +allow_zero_length_clientid false + +# Using ports 1884 and 8884, as the default ports seem to already be in use on Travis # Plain -bind_address 0.0.0.0 -port 1883 +bind_address localhost +port 1884 protocol mqtt # SSL -listener 8883 0.0.0.0 +listener 8884 localhost protocol mqtt -cafile .travis/certs/server.crt +cafile .travis/certs/ca.crt certfile .travis/certs/server.crt keyfile .travis/certs/server.key -#log_dest none +log_dest none diff --git a/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift b/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift index 2877012..1f8f18c 100644 --- a/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift +++ b/Tests/MQTTNIOTests/Core/MQTTNIOTestCase.swift @@ -24,13 +24,13 @@ class MQTTNIOTestCase: XCTestCase { var plainClient: MQTTClient { return MQTTClient(configuration: .init( - target: .host("0.0.0.0", port: 1883) + target: .host("localhost", port: 1884) ), eventLoopGroup: group) } var sslNoVerifyClient: MQTTClient { return MQTTClient(configuration: .init( - target: .host("0.0.0.0", port: 8883), + target: .host("localhost", port: 8884), tls: .forClient(certificateVerification: .none) ), eventLoopGroup: group) } @@ -41,14 +41,14 @@ class MQTTNIOTestCase: XCTestCase { .deletingLastPathComponent() .deletingLastPathComponent() .deletingLastPathComponent() - let certificateURL = rootDir.appendingPathComponent(".travis/certs/server.crt") - let certificate = try! NIOSSLCertificate.fromPEMFile(certificateURL.path)[0] + let caCertifcateURL = rootDir.appendingPathComponent(".travis/certs/ca.crt") + let caCertificate = try! NIOSSLCertificate.fromPEMFile(caCertifcateURL.path)[0] return MQTTClient(configuration: .init( - target: .host("0.0.0.0", port: 8883), + target: .host("localhost", port: 8884), tls: .forClient( certificateVerification: .noHostnameVerification, - trustRoots: .certificates([certificate]) + trustRoots: .certificates([caCertificate]) ) ), eventLoopGroup: group) } @@ -67,7 +67,7 @@ class MQTTNIOTestCase: XCTestCase { let isLoggingConfigured: Bool = { LoggingSystem.bootstrap { label in var handler = StreamLogHandler.standardOutput(label: label) - handler.logLevel = .trace + handler.logLevel = .error return handler } return true diff --git a/Tests/MQTTNIOTests/Core/TestUtils.swift b/Tests/MQTTNIOTests/Core/TestUtils.swift index b01483d..34cc9b3 100644 --- a/Tests/MQTTNIOTests/Core/TestUtils.swift +++ b/Tests/MQTTNIOTests/Core/TestUtils.swift @@ -11,15 +11,15 @@ func assertFailure(_ result: Result, file: StaticString = # extension XCTestCase { @discardableResult - func wait(for future: EventLoopFuture, timeout: TimeInterval = 2, file: StaticString = #file, line: UInt = #line) -> T { - var value: T! + func wait(for future: EventLoopFuture, timeout: TimeInterval = 2, file: StaticString = #file, line: UInt = #line) -> T? { + var value: T? let expectation = XCTestExpectation(description: "Waiting for future completion") future.whenComplete { result in assertSuccess(result, file: file, line: line) expectation.fulfill() - value = try! result.get() + value = try? result.get() } let expectationResult = XCTWaiter.wait(for: [expectation], timeout: timeout) diff --git a/Tests/MQTTNIOTests/Tests/PublishTests.swift b/Tests/MQTTNIOTests/Tests/PublishTests.swift index f7873ad..cc8f6ad 100644 --- a/Tests/MQTTNIOTests/Tests/PublishTests.swift +++ b/Tests/MQTTNIOTests/Tests/PublishTests.swift @@ -23,6 +23,8 @@ final class PublishTests: MQTTNIOTestCase { wait(for: client.publish(topic: topic, payload: payload, qos: qos)) wait(for: [expectation], timeout: 2) + + wait(for: client.disconnect()) } func testQoS1() throws { @@ -46,6 +48,8 @@ final class PublishTests: MQTTNIOTestCase { wait(for: client.publish(topic: topic, payload: payload, qos: qos)) wait(for: [expectation], timeout: 2) + + wait(for: client.disconnect()) } func testQoS2() throws { @@ -69,6 +73,8 @@ final class PublishTests: MQTTNIOTestCase { wait(for: client.publish(topic: topic, payload: payload, qos: qos)) wait(for: [expectation], timeout: 2) + + wait(for: client.disconnect()) } func testRetain() throws { @@ -78,6 +84,8 @@ final class PublishTests: MQTTNIOTestCase { let topic = "mqtt-nio/tests/retain" let payload = "Hello World!" + wait(for: client.publish(topic: topic, retain: true)) + let expectation1 = XCTestExpectation(description: "Received payload") client.addMessageListener { _, message, context in XCTAssertEqual(message.payloadString, payload) @@ -103,6 +111,8 @@ final class PublishTests: MQTTNIOTestCase { wait(for: client.subscribe(to: topic)) wait(for: [expectation2], timeout: 2) + + wait(for: client.disconnect()) } func testKeepSession() { @@ -126,6 +136,8 @@ final class PublishTests: MQTTNIOTestCase { wait(for: client.publish(topic: topic, payload: payload)) wait(for: [expectation], timeout: 2) + + wait(for: client.disconnect()) } func testMultiSubscribe() { @@ -138,10 +150,13 @@ final class PublishTests: MQTTNIOTestCase { MQTTSubscription(topic: "mqtt-nio/tests/multi-subscribe/3", qos: .exactlyOnce) ])) - XCTAssertEqual(results.count, 3) - XCTAssertEqual(results[0], .success(.atMostOnce)) - XCTAssertEqual(results[1], .success(.atLeastOnce)) - XCTAssertEqual(results[2], .success(.exactlyOnce)) + XCTAssertNotNil(results) + XCTAssertEqual(results!.count, 3) + XCTAssertEqual(results![0], .success(.atMostOnce)) + XCTAssertEqual(results![1], .success(.atLeastOnce)) + XCTAssertEqual(results![2], .success(.exactlyOnce)) + + wait(for: client.disconnect()) } func testUnsubscribe() { @@ -168,6 +183,8 @@ final class PublishTests: MQTTNIOTestCase { wait(seconds: 1) wait(for: [expectation], timeout: 2) + + wait(for: client.disconnect()) } func testKeepAlive() { @@ -182,6 +199,8 @@ final class PublishTests: MQTTNIOTestCase { XCTAssertTrue(client.isConnected) wait(for: client.publish(topic: topic, payload: payload)) + + wait(for: client.disconnect()) } func testInvalidClient() {