-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add IPv6 support This patch makes bridge accept IPv6 addresses as amqp_url value. * Committing clang-format changes * Eliminate implicit-function-declaration in tests * Correct character class in AMQP_URL_REGEX --------- Co-authored-by: InfraWatch CI <[email protected]> Co-authored-by: Chris Sibbitt <[email protected]> Co-authored-by: Victoria Martinez de la Cruz <[email protected]>
- Loading branch information
1 parent
85b865d
commit bf54f32
Showing
9 changed files
with
299 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Unit tests suite | ||
env: | ||
TEST_IMAGE: quay.io/centos/centos:stream9 | ||
PROJECT_ROOT: /src/github.com/infrawatch/sg-bridge | ||
OPSTOOLS_REPO: https://git.centos.org/rpms/centos-release-opstools/raw/c9s-sig-opstools/f/SOURCES/CentOS-OpsTools.repo | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
unit-tests: | ||
name: Unit tests | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Run sg-core unit test suite | ||
run: | | ||
docker run --name=testsuite -uroot --network host -e OPSTOOLS_REPO \ | ||
--volume ${{ github.workspace }}:$PROJECT_ROOT:z --workdir $PROJECT_ROOT \ | ||
$TEST_IMAGE bash $PROJECT_ROOT/ci/run_tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/env bash | ||
# purpose: runt unit test suite | ||
|
||
set -ex | ||
|
||
# enable required repo(s) | ||
dnf install -y centos-release-opstools tree | ||
dnf install make gcc qpid-proton-c-devel annobin-annocheck gcc-plugin-annobin rpm-build -y | ||
|
||
make tests | ||
./tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* taken from https://jera.com/techinfo/jtns/jtn002 | ||
*/ | ||
|
||
/* file: minunit.h */ | ||
#define mu_assert(message, test) \ | ||
do { \ | ||
if (!(test)) \ | ||
return message; \ | ||
} while (0) | ||
#define mu_run_test(test) \ | ||
do { \ | ||
char *message = test(); \ | ||
tests_run++; \ | ||
if (message) \ | ||
return message; \ | ||
} while (0) | ||
extern int tests_run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Copyright 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain | ||
* a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
#include "bridge.h" | ||
#include "minunit.h" | ||
#include "utils.h" | ||
#include <stdio.h> | ||
|
||
/***************** test suite *****************/ | ||
|
||
static char *test_match_amqp_url_hostname() { | ||
char *matches[10]; | ||
memset(matches, 0, sizeof(matches)); | ||
match_regex(AMQP_URL_REGEX, matches, 10, | ||
"amqp://scooby:[email protected]:5666/foo/bar"); | ||
|
||
mu_assert("Failed to parse full amqp_url in form of hostname: user", | ||
!strcmp(matches[3], "scooby")); | ||
mu_assert("Failed to parse full amqp_url in form of hostname: password", | ||
!strcmp(matches[5], "doo")); | ||
mu_assert("Failed to parse full amqp_url in form of hostname: host", | ||
!strcmp(matches[6], "some.k8s.svc")); | ||
mu_assert("Failed to parse full amqp_url in form of hostname: port", | ||
!strcmp(matches[8], "5666")); | ||
mu_assert("Failed to parse full amqp_url in form of hostname: address", | ||
!strcmp(matches[9], "/foo/bar")); | ||
|
||
char *matches2[10]; | ||
memset(matches2, 0, sizeof(matches2)); | ||
match_regex(AMQP_URL_REGEX, matches2, 10, "amqps://other.k8s.svc:5666/baz"); | ||
|
||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of hostname: user", | ||
matches2[3] == NULL); | ||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of hostname: password", | ||
matches2[5] == NULL); | ||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of hostname: host", | ||
!strcmp(matches2[6], "other.k8s.svc")); | ||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of hostname: port", | ||
!strcmp(matches2[8], "5666")); | ||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of hostname: address", | ||
!strcmp(matches2[9], "/baz")); | ||
|
||
return 0; | ||
} | ||
|
||
static char *test_match_amqp_url_ipv4() { | ||
char *matches[10]; | ||
memset(matches, 0, sizeof(matches)); | ||
match_regex(AMQP_URL_REGEX, matches, 10, | ||
"amqp://scooby:[email protected]:5666/foo/bar"); | ||
|
||
mu_assert("Failed to parse amqp_url in form of IPv4: user invalid: %s", | ||
!strcmp(matches[3], "scooby")); | ||
mu_assert("Failed to parse amqp_url in form of IPv4: password", | ||
!strcmp(matches[5], "doo")); | ||
mu_assert("Failed to parse amqp_url in form of IPv4:i host", | ||
!strcmp(matches[6], "127.0.0.1")); | ||
mu_assert("Failed to parse amqp_url in form of IPv4: port", | ||
!strcmp(matches[8], "5666")); | ||
mu_assert("Failed to parse amqp_url in form of IPv4: address", | ||
!strcmp(matches[9], "/foo/bar")); | ||
|
||
char *matches2[10]; | ||
memset(matches2, 0, sizeof(matches2)); | ||
match_regex(AMQP_URL_REGEX, matches2, 10, "amqps://127.0.0.1:5666/baz"); | ||
|
||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv4: user", | ||
matches2[3] == NULL); | ||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of IPv4: password", | ||
matches2[5] == NULL); | ||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv4: host", | ||
!strcmp(matches2[6], "127.0.0.1")); | ||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv4: port", | ||
!strcmp(matches2[8], "5666")); | ||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv4: address", | ||
!strcmp(matches2[9], "/baz")); | ||
return 0; | ||
} | ||
|
||
static char *test_match_amqp_url_ipv6() { | ||
char *matches[10]; | ||
memset(matches, 0, sizeof(matches)); | ||
match_regex(AMQP_URL_REGEX, matches, 10, | ||
"amqp://scooby:doo@[fe80::abcd:fcff:fe07:9999]:5666/foo/bar"); | ||
|
||
mu_assert("Failed to parse amqp_url in form of IPv6: user", | ||
!strcmp(matches[3], "scooby")); | ||
mu_assert("Failed to parse amqp_url in form of IPv6: password", | ||
!strcmp(matches[5], "doo")); | ||
mu_assert("Failed to parse amqp_url in form of IPv6: host", | ||
!strcmp(matches[6], "[fe80::abcd:fcff:fe07:9999]")); | ||
mu_assert("Failed to parse amqp_url in form of IPv6: port", | ||
!strcmp(matches[8], "5666")); | ||
mu_assert("Failed to parse amqp_url in form of IPv6: address", | ||
!strcmp(matches[9], "/foo/bar")); | ||
|
||
char *matches2[10]; | ||
memset(matches2, 0, sizeof(matches2)); | ||
match_regex(AMQP_URL_REGEX, matches2, 10, | ||
"amqps://[fe80::abcd:fcff:fe07:9999]:5666/bas"); | ||
|
||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv6: user", | ||
matches2[3] == NULL); | ||
mu_assert( | ||
"Failed to parse amqp_url w/o user info in form of IPv6: password", | ||
matches2[5] == NULL); | ||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv6: host", | ||
!strcmp(matches2[6], "[fe80::abcd:fcff:fe07:9999]")); | ||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv6: port", | ||
!strcmp(matches2[8], "5666")); | ||
mu_assert("Failed to parse amqp_url w/o user info in form of IPv6: address", | ||
!strcmp(matches2[9], "/bas")); | ||
return 0; | ||
} | ||
|
||
static char *test_match_amqp_url_fail() { | ||
char *matches[10]; | ||
memset(matches, 0, sizeof(matches)); | ||
match_regex(AMQP_URL_REGEX, matches, 10, | ||
"amqp://scooby:doo@[XXX.666.000.123/64]:5666/foo/bar"); | ||
|
||
mu_assert("Failed to fail parsing invalid amqp_url", | ||
matches[6] == NULL && matches[9] == NULL); | ||
return 0; | ||
} | ||
|
||
/******************* runner *******************/ | ||
|
||
int tests_run = 0; | ||
|
||
static char *all_tests() { | ||
mu_run_test(test_match_amqp_url_hostname); | ||
mu_run_test(test_match_amqp_url_ipv4); | ||
mu_run_test(test_match_amqp_url_ipv6); | ||
mu_run_test(test_match_amqp_url_fail); | ||
return 0; | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
char *result = all_tests(); | ||
if (result != 0) { | ||
printf("%s\n", result); | ||
} else { | ||
printf("ALL TESTS PASSED\n"); | ||
} | ||
printf("Tests run: %d\n", tests_run); | ||
|
||
return result != 0; | ||
} |
Oops, something went wrong.