Skip to content

Commit

Permalink
Switched from BSON to JSON as a data interchange format
Browse files Browse the repository at this point in the history
  • Loading branch information
mbish committed Feb 2, 2022
1 parent 77a88ec commit 9bbef47
Show file tree
Hide file tree
Showing 26 changed files with 5,636 additions and 322 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Makefile.in
test.conf
__pycache__/
Vagrantfile
.isort.cfg
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include:
---
include:
- project: "mirrors/duo_unix_ci"
ref: "master"
file: ".gitlab-ci.yml"
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
duo_unix-1.12.0:
- Switched from BSON to JSON as a data interchange format
- Switched from Cram to python `unittest` for testing

duo_unix-1.11.5:
- Added support for Debian 11
- Removed support for Debian 8
Expand Down
36 changes: 19 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Install the necessary third party libraries.

- Debian based Systems
```
$ sudo apt-get install autoconf libtool libpam-dev libssl-dev
$ sudo apt-get install autoconf libtool libpam-dev libssl-dev make
```

- RHEL based systems
Expand Down Expand Up @@ -98,28 +98,31 @@ To run all the automated tests simply run
```
$ make check
```

To run an individual test
To run an individual test file
```
$ cd tests/
$ python cram.py login_duo-1.t
$ python test_login_duo.py
```

### Cram Tests

For Duo Unix we use [Cram](https://bitheap.org/cram/) to do our testing. Each test file typically starts by creating a mock duo service. After we create that service we list commands followed by the expected output of that command.
If the output matches, then the cram test passes. If not, it fails.

Example passing test
To run an individual test suite
```
$ echo "Hello World"
Hello World
$ cd tests/
$ python test_login_duo.py TestLoginDuoConfig
```
Example failing test
To run an individual test case
```
$ echo "Hello World"
Goodbye World
$ cd tests/
$ python test_login_duo.py TestLoginDuoConfig.test_empty_args
```

### Python Tests

For Duo Unix we use the python `unittest` library to do our testing. Each suite
typically starts by creating a mock duo service. After we create that service
we perform a series of tests to verify that this software is working as
expected. Although we use the `unittest` library these are not truely "unit tests"
as manage subprocesses and generally employ blackbox testing. The true "unit tests"
for Duo Unix are the unity tests.

### Testing with coverage
To generate coverate reports you'll need to compile Duo Unix with the `--with-coverage` options.
Please note that in order to view HTML version of the coverage reports you'll also need to
Expand All @@ -132,7 +135,6 @@ $ ./configure --with-coverage --with-pam
$ ./collect_coverage.sh
$ $BROWSER coverage/pam_duo.html
```
```
Note that configuring Duo Unix --with-coverage disables any compiler optimizations
to allow the profiler to better match executed instructions with lines of code.

Expand Down
80 changes: 80 additions & 0 deletions collect_coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
# Run this at the root of a Duo Unix directory that has been compiled with coverage
# reporting turned on

if ! [ -x "$(command -v gcovr)" ]; then
echo "Missing gcovr. Please pip install"
exit 1
fi

mkdir -p coverage

# This section is necessary because otherwise coverage files are created with a
# file mode of 0100 (due to an issue with linking to compat) which causes
# errors. To "get ahead of this" we are creating the coverage files and setting
# their file mode to 700 this allows us to have full coverage and avoid errors.

mkdir -p tests/.libs
GCDA_FILES=(
"/vagrant/pam_duo/.libs/pam_duo_private.gcda"
"/vagrant/pam_duo/.libs/pam_duo.gcda"
"/vagrant/tests/testpam.gcda"
"/vagrant/tests/.libs/testpam_preload.gcda"
"/vagrant/pam_duo/.libs/pam_duo_private.gcda"
"/vagrant/pam_duo/.libs/pam_duo.gcda"
"/vagrant/tests/testpam.gcda"
"/vagrant/tests/.libs/testpam_preload.gcda"
"/vagrant/lib/.libs/http_parser.gcda"
"/vagrant/lib/.libs/bson.gcda"
"/vagrant/lib/.libs/urlenc.gcda"
"/vagrant/lib/.libs/ini.gcda"
"/vagrant/lib/.libs/https.gcda"
"/vagrant/lib/.libs/duo.gcda"
)

for i in "${GCDA_FILES[@]}"; do
rm -f "$i"; touch "$i"; chmod 700 "$i"
done

# end weird permission hacking

make check
gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o coverage/coverage.xml --root .

if [ -f pam_duo/pam_duo.gcno ]; then
(
cd pam_duo || return
gcov pam_duo.c -o .libs
gcovr --txt
gcovr --html-details pam_duo.html
rm -f .libs/*.gcda
)
mv pam_duo/*.{css,html} coverage
else
echo "No coverage information found for pam_duo.c"
fi
if [ -f login_duo/login_duo.gcno ]; then
(
cd login_duo || return
gcov login_duo.c
gcovr --txt
gcovr --html-details login_duo.html
gcovr --xml-pretty --exclude-unreachable-branches --print-summary -o login_duo.xml --root ${CI_PROJECT_DIR}
rm -f *.gcda
)
mv login_duo/*.{css,html} coverage
else
echo "No coverage information found for login_duo.c"
fi
if [ -f lib/duo.gcno ]; then
(
cd lib || return
gcov duo.c -o .libs
gcovr --txt
gcovr --html-details duo.html
rm -f .libs/*.gcda
)
mv lib/*.{css,html} coverage
else
echo "No coverage information found for duo.c"
fi
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ AC_PREREQ(2.65)

# Package, version, bug report address
AC_INIT([duo_unix],
[1.11.5],
[1.12.0],
[[email protected]])

# Tells autoconf where to find necessary build scripts and macros.
Expand Down Expand Up @@ -60,6 +60,7 @@ case "$host_os" in
;;
*aix*)
AC_MSG_NOTICE([-fstack-protector disabled on AIX])
CFLAGS="$CFLAGS -Wl,-lm"
has_stack_protector=no
IS_AIX=yes
;;
Expand Down
2 changes: 1 addition & 1 deletion lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ noinst_LTLIBRARIES = libduo.la

libduo_la_SOURCES = bson.h bson.c cacert.h duo.c \
http_parser.h http_parser.c https.h https.c ini.h ini.c \
urlenc.h urlenc.c util.c
urlenc.h urlenc.c util.c parson.h parson.c
libduo_la_LIBADD = @OPENSSL_LDFLAGS@ @OPENSSL_LIBS@
# http://sourceware.org/autobook/autobook/autobook_91.html
libduo_la_LDFLAGS = -no-undefined -version-info 3:0:0 -export-symbols-regex '^duo_'
Expand Down
Loading

0 comments on commit 9bbef47

Please sign in to comment.