Skip to content

Commit 12d56b0

Browse files
committed
test: add test
1 parent df60fb1 commit 12d56b0

File tree

9 files changed

+143
-12
lines changed

9 files changed

+143
-12
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,3 @@ debian/howdy
125125

126126
# Built Visual Studio Code Extensions
127127
*.vsix
128-
129-
# Meson
130-
subprojects/

howdy/src/pam/meson.build

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ subdir('po')
1010
paths_h = configure_file(
1111
input: 'paths.hh.in',
1212
output: 'paths.hh',
13-
configuration: pam_module_conf_data
13+
configuration: pam_module_conf_data,
1414
)
1515

16-
pamdir = get_option('pam_dir') != '' ? get_option('pam_dir') : join_paths(get_option('prefix'), get_option('libdir'), 'security')
16+
pamdir = (
17+
get_option('pam_dir') != '' ? get_option('pam_dir') : join_paths(
18+
get_option('prefix'),
19+
get_option('libdir'),
20+
'security',
21+
)
22+
)
1723

18-
shared_library(
24+
pam_howdy_lib = shared_library(
1925
'pam_howdy',
2026
'main.cc',
2127
'enter_device.cc',
@@ -31,5 +37,7 @@ shared_library(
3137
install: true,
3238
install_dir: pamdir,
3339
install_tag: 'pam_module',
34-
name_prefix: ''
40+
name_prefix: '',
3541
)
42+
43+
subdir('tests')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[wrap-file]
2+
directory = argparse-3.0
3+
source_url = https://github.com/p-ranav/argparse/archive/refs/tags/v3.0.tar.gz
4+
source_filename = argparse-3.0.tar.gz
5+
source_hash = ba7b465759bb01069d57302855eaf4d1f7d677f21ad7b0b00b92939645c30f47
6+
patch_filename = argparse_3.0-1_patch.zip
7+
patch_url = https://wrapdb.mesonbuild.com/v2/argparse_3.0-1/get_patch
8+
patch_hash = f83ed766f07c830d3922676c67959f2078a055c07bd360f19e0e114d375d1037
9+
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/argparse_3.0-1/argparse-3.0.tar.gz
10+
wrapdb_version = 3.0-1
11+
12+
[provide]
13+
argparse = argparse_dep
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
auth sufficient @howdy_path@

howdy/src/pam/tests/meson.build

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
gtest = dependency('gtest')
2+
gtest_main = dependency('gtest_main')
3+
libpamtest = dependency('libpamtest')
4+
5+
testpam_module_conf_data = configuration_data(paths_dict)
6+
testpam_module_conf_data.set(
7+
'compare_script_path',
8+
join_paths(pysourcesinstalldir, 'compare.py'),
9+
)
10+
11+
test_config = configure_file(
12+
input: '../../config.ini',
13+
output: 'config.ini',
14+
copy: true,
15+
)
16+
17+
testpam_module_conf_data.set('config_file_path', test_config.full_path())
18+
19+
testpaths_h = configure_file(
20+
input: '../paths.hh.in',
21+
output: 'paths.hh',
22+
configuration: testpam_module_conf_data,
23+
)
24+
25+
shared_library(
26+
'pam_howdytest',
27+
'../main.cc',
28+
'../enter_device.cc',
29+
dependencies: [
30+
libpam,
31+
inih_cpp,
32+
threads,
33+
libevdev,
34+
],
35+
link_depends: [
36+
testpaths_h,
37+
],
38+
install: true,
39+
install_dir: pamdir,
40+
install_tag: 'pam_module',
41+
name_prefix: '',
42+
)
43+
44+
configure_file(
45+
input: 'howdy_service.in',
46+
output: 'howdy_service',
47+
configuration: {'howdy_path': pam_howdy_lib.full_path()},
48+
)
49+
50+
51+
# Build the module test executable
52+
e = executable(
53+
'test_module',
54+
'test_module.cc',
55+
testpaths_h,
56+
dependencies: [gtest, gtest_main, libpamtest],
57+
)
58+
59+
test(
60+
'test_module',
61+
e,
62+
env: {'PAM_WRAPPER': '1', 'PAM_WRAPPER_SERVICE_DIR': '.'},
63+
)

howdy/src/pam/tests/test_enter_device.cc

Whitespace-only changes.

howdy/src/pam/tests/test_module.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <fstream>
2+
#include <gtest/gtest.h>
3+
#include <security/_pam_types.h>
4+
extern "C" {
5+
#include <libpamtest.h>
6+
}
7+
#include <paths.hh>
8+
9+
TEST(CheckEnabled, StopDisabled) {
10+
std::ofstream config(CONFIG_FILE_PATH);
11+
config << "enabled = false";
12+
config.close();
13+
14+
enum pamtest_err perr;
15+
struct pamtest_conv_data conv_data = {};
16+
17+
// NOLINTNEXTLINE
18+
struct pam_testcase tests[] = {pam_test(PAMTEST_AUTHENTICATE, PAM_AUTHINFO_UNAVAIL)};
19+
20+
perr = run_pamtest("howdy_service", "test", &conv_data, tests, nullptr);
21+
pamtest_failed_case(tests);
22+
EXPECT_EQ(perr, PAMTEST_ERR_OK);
23+
}

meson.build

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
1-
project('howdy', 'cpp', license: 'MIT', version: 'beta', meson_version: '>= 0.64.0')
1+
project(
2+
'howdy',
3+
'cpp',
4+
'c',
5+
license: 'MIT',
6+
version: 'beta',
7+
meson_version: '>= 0.64.0',
8+
)
29

3-
dlibdatadir = get_option('dlib_data_dir') != '' ? get_option('dlib_data_dir') : join_paths(get_option('prefix'), get_option('datadir'), 'dlib-data')
4-
confdir = get_option('config_dir') != '' ? get_option('config_dir') : join_paths(get_option('prefix'), get_option('sysconfdir'), 'howdy')
5-
usermodelsdir = get_option('user_models_dir') != '' ? get_option('user_models_dir') : join_paths(confdir, 'models')
10+
dlibdatadir = (
11+
get_option('dlib_data_dir') != '' ? get_option('dlib_data_dir') : join_paths(
12+
get_option('prefix'),
13+
get_option('datadir'),
14+
'dlib-data',
15+
)
16+
)
17+
confdir = (
18+
get_option('config_dir') != '' ? get_option('config_dir') : join_paths(
19+
get_option('prefix'),
20+
get_option('sysconfdir'),
21+
'howdy',
22+
)
23+
)
24+
usermodelsdir = (
25+
get_option('user_models_dir') != '' ? get_option('user_models_dir') : join_paths(
26+
confdir,
27+
'models',
28+
)
29+
)
630
logpath = get_option('log_path')
731

832
config_path = join_paths(confdir, 'config.ini')
@@ -16,4 +40,4 @@ paths_dict = {
1640

1741
# We need to keep this order beause howdy-gtk defines the gtk script path
1842
subdir('howdy-gtk')
19-
subdir('howdy')
43+
subdir('howdy')

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[project]
2+
name = "howdy"

0 commit comments

Comments
 (0)