mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
Merge pull request #5 from falk-werner/test_and_docu
refactored unit tests
This commit is contained in:
commit
563cbf5296
@ -119,27 +119,39 @@ include(GoogleTest)
|
||||
pkg_check_modules(GMOCK gmock)
|
||||
|
||||
add_executable(alltests
|
||||
test/mock_config_builder.cc
|
||||
test/mock_logger.cc
|
||||
test/mock_credentials.cc
|
||||
test/mock_settings.cc
|
||||
test/mock_pam.cc
|
||||
test/test_config_factory.cc
|
||||
test/test_config.cc
|
||||
test/test_settings.cc
|
||||
test/test_auth_factory.cc
|
||||
test/test_file_authenticator.cc
|
||||
test/test_pam_authenticator.cc
|
||||
test/test_mountpoint_factory.cc
|
||||
test/test_log.cc
|
||||
test/test_log_manager.cc
|
||||
test/test_stderr_logger.cc
|
||||
test/test_syslog_logger.cc
|
||||
test/test_daemon.cc
|
||||
test/mock/config_builder.cc
|
||||
test/mock/logger.cc
|
||||
test/mock/credentials.cc
|
||||
test/mock/settings.cc
|
||||
test/mock/pam.cc
|
||||
test/mock/libconfig.cc
|
||||
test/mock/linux.cc
|
||||
test/mock/server.cc
|
||||
test/config/configfile.cc
|
||||
test/config/configfile_version.cc
|
||||
test/config/configfile_server.cc
|
||||
test/config/configfile_auth.cc
|
||||
test/config/configfile_filesystem.cc
|
||||
test/config/configfile_log.cc
|
||||
test/config/configfile_user.cc
|
||||
test/config/config.cc
|
||||
test/config/settings.cc
|
||||
test/auth/factory.cc
|
||||
test/auth/file_authenticator.cc
|
||||
test/auth/pam_authenticator.cc
|
||||
test/log/log.cc
|
||||
test/log/log_manager.cc
|
||||
test/log/stderr_logger.cc
|
||||
test/log/syslog_logger.cc
|
||||
test/daemon.cc
|
||||
test/change_user.cc
|
||||
test/mountpoint_factory.cc
|
||||
test/userdb.cc
|
||||
)
|
||||
|
||||
target_include_directories(alltests PRIVATE
|
||||
src
|
||||
test
|
||||
${GMOCK_INCLUDE_DIRS}
|
||||
${GTEST_INCLUDE_DIRS}
|
||||
)
|
||||
@ -150,6 +162,8 @@ target_link_libraries(alltests PRIVATE
|
||||
-Wl,--wrap=wf_credentials_type
|
||||
-Wl,--wrap=wf_credentials_get
|
||||
|
||||
-Wl,--wrap=wf_server_create
|
||||
|
||||
-Wl,--wrap=wfd_settings_get_string
|
||||
-Wl,--wrap=wfd_settings_get_string_or_default
|
||||
-Wl,--wrap=wfd_settings_get_bool
|
||||
@ -172,6 +186,15 @@ target_link_libraries(alltests PRIVATE
|
||||
-Wl,--wrap=pam_authenticate
|
||||
-Wl,--wrap=pam_acct_mgmt
|
||||
|
||||
-Wl,--wrap=config_setting_get_elem
|
||||
|
||||
-Wl,--wrap=getuid
|
||||
-Wl,--wrap=getgrnam
|
||||
-Wl,--wrap=setgid
|
||||
-Wl,--wrap=setgroups
|
||||
-Wl,--wrap=getpwnam
|
||||
-Wl,--wrap=setuid
|
||||
|
||||
webfused-static
|
||||
userdb
|
||||
${LIBCONFIG_LIBRARIES}
|
||||
@ -197,7 +220,7 @@ add_custom_target(check
|
||||
add_dependencies(check alltests)
|
||||
|
||||
add_custom_target(memcheck
|
||||
valgrind ./alltests)
|
||||
valgrind --leak-check=full --error-exitcode=1 ./alltests)
|
||||
add_dependencies(memcheck alltests)
|
||||
|
||||
add_custom_target(coverage
|
||||
|
273
README.md
273
README.md
@ -1,269 +1,18 @@
|
||||
[![Build Status](https://travis-ci.org/falk-werner/webfused.svg?branch=master)](https://travis-ci.org/falk-werner/webfused)
|
||||
[![codecov](https://codecov.io/gh/falk-werner/webfused/branch/config_file/graph/badge.svg)](https://codecov.io/gh/falk-werner/webfused)
|
||||
[![codecov](https://codecov.io/gh/falk-werner/webfused/branch/master/graph/badge.svg)](https://codecov.io/gh/falk-werner/webfused)
|
||||
|
||||
# webfused
|
||||
# Webfuse Daemon
|
||||
|
||||
Reference implementation of webfuse daemon.
|
||||
Reference implementation of webfuse daemon (webfused).
|
||||
|
||||
## Build and run
|
||||
## Further information
|
||||
|
||||
To install dependecies, see below.
|
||||
- [Build Instructions](doc/build.md)
|
||||
- [Configuration](doc/config.md)
|
||||
- [Webfuse Protocol Specification](https://github.com/falk-werner/webfuse/blob/master/doc/protocol.md)
|
||||
|
||||
cd webfused
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
./webfused -f webfused.conf
|
||||
## Fellow Repositories
|
||||
|
||||
## Config file
|
||||
|
||||
```
|
||||
version = { major = 1, minor = 0 }
|
||||
|
||||
server:
|
||||
{
|
||||
vhost_name = "localhost"
|
||||
port = 8080
|
||||
|
||||
tls:
|
||||
{
|
||||
certificate = "/etc/webfused/cert.pem"
|
||||
|
||||
key = "/etc/webfused/key.pem"
|
||||
}
|
||||
|
||||
document_root = "/var/www"
|
||||
}
|
||||
|
||||
authentication:
|
||||
(
|
||||
{
|
||||
provider = "pam"
|
||||
settings:
|
||||
{
|
||||
service_name = "webfused"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
filesystems:
|
||||
(
|
||||
{name = "test", mount_point = "/tmp/webfused" }
|
||||
)
|
||||
|
||||
log:
|
||||
{
|
||||
provider: "syslog"
|
||||
level: "warning"
|
||||
settings:
|
||||
{
|
||||
ident = "webfused"
|
||||
facility = "daemon"
|
||||
log_pid = true
|
||||
}
|
||||
}
|
||||
|
||||
user:
|
||||
{
|
||||
name = "webfused"
|
||||
group = "webfused"
|
||||
}
|
||||
```
|
||||
|
||||
### Version
|
||||
|
||||
The version sections specifies the schema version of the config file.
|
||||
Currently, there is only one schema version defined: 1.0
|
||||
|
||||
### Server
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ------------- | ------ | ------------- | ------------------------ |
|
||||
| vhostname | string | localhost | Name of the virtual host |
|
||||
| port | int | 8080 | Port number of server |
|
||||
| document_root | string | *-empty-* | Path of HTTP files |
|
||||
| tls | object | *-empty-* | see below |
|
||||
|
||||
When *document_root* is omitted, no HTTP files are served.
|
||||
|
||||
#### TLS
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | ------------------------------------------- |
|
||||
| certificate | string | *-empty-* | Path to servers own certificate (.pem file) |
|
||||
| key | string | *-empty-* | Path to servers own private key (.pem file) |
|
||||
|
||||
TLS is only activated, when both, *certificate* and *key* are specified.
|
||||
Otherwise, plain websockes without TLS are used.
|
||||
|
||||
### Authentication
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| -------- | ------ | ------------- | ----------------------------------------------- |
|
||||
| provider | string | *-required-* | Name of the authentication provider (see below) |
|
||||
| settings | object | *-empty-* | Provider specific settings (see below)
|
||||
|
||||
Currently, the following providers are supported:
|
||||
|
||||
- *file*: file based authentication
|
||||
- *pam*: authentication based on Linux PAM
|
||||
|
||||
### File Authenticaton Provider
|
||||
|
||||
Allows authentication against a file containing username and password.
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| -------- | ------ | ------------- | ------------------------------- |
|
||||
| file | string | *-required-* | Path to the authentication file |
|
||||
|
||||
### PAM Authenticaton Provider
|
||||
|
||||
Allows authentication using Linux PAM.
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ------------ | ------ | ------------- | ---------------------- |
|
||||
| service_name | string | webfused | PAM service identifier |
|
||||
|
||||
### Filesystems
|
||||
|
||||
Contains a list of file systems that can be provided by webfuse providers.
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | ---------------------------------- |
|
||||
| name | string | *-required-* | Name of the filesystem |
|
||||
| mount_point | string | *-required-* | Local path to mount the filesystem |
|
||||
|
||||
### Log
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | -------------------------------------- |
|
||||
| provider | string | *-required-* | Name of log provider (see below) |
|
||||
| level | string | *-required-* | Log level (see below) |
|
||||
| settings | object | *-empty-* | Provider specific settings (see below) |
|
||||
|
||||
The following log levels are supported:
|
||||
|
||||
- *none*: diabled logging
|
||||
- *fatal*: log only fatal errors
|
||||
- *error*: log all kind of errors
|
||||
- *warn*: log errors and warnings
|
||||
- *info*: log info messages, warnings and errors
|
||||
- *debug*: log debug and info messages as well as warnings and errors
|
||||
- *all*: log all kind of messages
|
||||
|
||||
Currently, the following providers are available:
|
||||
|
||||
- *stderr*: logs to console error output
|
||||
- *syslog*: logs to syslog
|
||||
|
||||
#### Stderr Logger
|
||||
|
||||
This logger does not provide any settings.
|
||||
|
||||
#### Syslog Logger
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | ------------------------------------------ |
|
||||
| ident | string | webfused | Syslog ident (see syslog documentation) |
|
||||
| facility | string | daemon | Syslog facility (see syslog documentation) |
|
||||
| log_pid | bool | false | Add process ID to log messages |
|
||||
|
||||
### User
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ------- | ------ | ------------- | ------------------------------- |
|
||||
| name | string | *-required-* | Name of the user to switch to. |
|
||||
| group | string | *-required-* | Name of the group to switch to. |
|
||||
|
||||
Webfuse daemon will not run as root. If started as root, webfuse daemon tries to
|
||||
switch to *user* and *group* provided in config file.
|
||||
|
||||
*Note*: user and group are not switched, when webfuse daemon is not started as root.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [webfuse](https://github.com/falk-werner/webfuse)
|
||||
- [libfuse](https://github.com/libfuse/libfuse/)
|
||||
- [libwebsockets](https://libwebsockets.org/)
|
||||
- [jansson](https://github.com/akheron/jansson)
|
||||
- [openssl](https://www.openssl.org/)
|
||||
- [libconfig](https://hyperrealm.github.io/libconfig/)
|
||||
- [linux-pam](http://www.linux-pam.org/)
|
||||
- [Google Test](https://github.com/google/googletest) *(Test only)*
|
||||
|
||||
### Installing dependencies
|
||||
|
||||
#### libfuse
|
||||
|
||||
To install libfuse, meson is needed. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions.
|
||||
|
||||
wget https://github.com/libfuse/libfuse/archive/fuse-3.9.0.tar.gz -O fuse.tar.gz
|
||||
tar -xf fuse.tar.gz
|
||||
cd libfuse-fuse-3.9.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
meson ..
|
||||
ninja
|
||||
sudo ninja install
|
||||
|
||||
#### libwebsockets
|
||||
|
||||
wget https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz -O libwebsockets.tar.gz
|
||||
tar -xf libwebsockets.tar.gz
|
||||
cd libwebsockets-3.2.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
|
||||
#### jansson
|
||||
|
||||
wget https://github.com/akheron/jansson/archive/v2.12.tar.gz -O jansson.tar.gz
|
||||
tar -xf jansson.tar.gz
|
||||
cd jansson-2.12
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
|
||||
#### openssl
|
||||
|
||||
sudo apt update
|
||||
sudo install openssl libssl-dev
|
||||
|
||||
#### webfuse
|
||||
|
||||
wget https://github.com/falk-werner/webfuse/archive/v0.2.0.tar.gz -O webfuse.tar.gz
|
||||
tar -xf webfuse.tar.gz
|
||||
cd webfuse-0.2.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake -DWITHOUT_TESTS=ON ..
|
||||
make
|
||||
sudo make install
|
||||
|
||||
#### libconfig
|
||||
|
||||
sudo apt update
|
||||
sudo apt install libconfig-dev
|
||||
|
||||
#### linux-pam
|
||||
|
||||
sudo apt update
|
||||
sudo apt install libpam0g-dev
|
||||
|
||||
#### GoogleTest
|
||||
|
||||
Installation of GoogleTest is optional webfuse library, but required to compile tests.
|
||||
|
||||
wget -O gtest-1.10.0.tar.gz https://github.com/google/googletest/archive/release-1.10.0.tar.gz
|
||||
tar -xf gtest-1.10.0.tar.gz
|
||||
cd googletest-release-1.10.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
- **[webfuse](https://github.com/falk-werner/webfuse)**: webfuse library
|
||||
- **[webfuse-example](https://github.com/falk-werner/webfuse-example)**: example of webfuse
|
||||
- **[webfuse-provider](https://github.com/falk-werner/webfuse-provider)**: reference implementation of webfuse provider
|
||||
|
95
doc/build.md
Normal file
95
doc/build.md
Normal file
@ -0,0 +1,95 @@
|
||||
# Build Instructions
|
||||
|
||||
To install dependecies, see below.
|
||||
|
||||
cd webfused
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
./webfused -f webfused.conf
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [webfuse](https://github.com/falk-werner/webfuse)
|
||||
- [libfuse](https://github.com/libfuse/libfuse/)
|
||||
- [libwebsockets](https://libwebsockets.org/)
|
||||
- [jansson](https://github.com/akheron/jansson)
|
||||
- [openssl](https://www.openssl.org/)
|
||||
- [libconfig](https://hyperrealm.github.io/libconfig/)
|
||||
- [linux-pam](http://www.linux-pam.org/)
|
||||
- [Google Test](https://github.com/google/googletest) *(Test only)*
|
||||
|
||||
### libfuse
|
||||
|
||||
To install libfuse, meson is needed. Please refer to [meson quick guide](https://mesonbuild.com/Quick-guide.html) for setup instructions.
|
||||
|
||||
wget https://github.com/libfuse/libfuse/archive/fuse-3.9.0.tar.gz -O fuse.tar.gz
|
||||
tar -xf fuse.tar.gz
|
||||
cd libfuse-fuse-3.9.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
meson ..
|
||||
ninja
|
||||
sudo ninja install
|
||||
|
||||
### libwebsockets
|
||||
|
||||
wget https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz -O libwebsockets.tar.gz
|
||||
tar -xf libwebsockets.tar.gz
|
||||
cd libwebsockets-3.2.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
|
||||
### jansson
|
||||
|
||||
wget https://github.com/akheron/jansson/archive/v2.12.tar.gz -O jansson.tar.gz
|
||||
tar -xf jansson.tar.gz
|
||||
cd jansson-2.12
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
||||
|
||||
### openssl
|
||||
|
||||
sudo apt update
|
||||
sudo install openssl libssl-dev
|
||||
|
||||
### webfuse
|
||||
|
||||
wget https://github.com/falk-werner/webfuse/archive/v0.2.0.tar.gz -O webfuse.tar.gz
|
||||
tar -xf webfuse.tar.gz
|
||||
cd webfuse-0.2.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake -DWITHOUT_TESTS=ON ..
|
||||
make
|
||||
sudo make install
|
||||
|
||||
### libconfig
|
||||
|
||||
sudo apt update
|
||||
sudo apt install libconfig-dev
|
||||
|
||||
### linux-pam
|
||||
|
||||
sudo apt update
|
||||
sudo apt install libpam0g-dev
|
||||
|
||||
### GoogleTest
|
||||
|
||||
Installation of GoogleTest is optional webfuse library, but required to compile tests.
|
||||
|
||||
wget -O gtest-1.10.0.tar.gz https://github.com/google/googletest/archive/release-1.10.0.tar.gz
|
||||
tar -xf gtest-1.10.0.tar.gz
|
||||
cd googletest-release-1.10.0
|
||||
mkdir .build
|
||||
cd .build
|
||||
cmake ..
|
||||
make
|
||||
sudo make install
|
168
doc/config.md
Normal file
168
doc/config.md
Normal file
@ -0,0 +1,168 @@
|
||||
# Configuration
|
||||
|
||||
A config file is used to configure webfuse daemon.
|
||||
|
||||
## Config file
|
||||
|
||||
```
|
||||
version = { major = 1, minor = 0 }
|
||||
|
||||
server:
|
||||
{
|
||||
vhost_name = "localhost"
|
||||
port = 8080
|
||||
|
||||
tls:
|
||||
{
|
||||
certificate = "/etc/webfused/cert.pem"
|
||||
|
||||
key = "/etc/webfused/key.pem"
|
||||
}
|
||||
|
||||
document_root = "/var/www"
|
||||
}
|
||||
|
||||
authentication:
|
||||
(
|
||||
{
|
||||
provider = "pam"
|
||||
settings:
|
||||
{
|
||||
service_name = "webfused"
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
filesystems:
|
||||
(
|
||||
{name = "test", mount_point = "/tmp/webfused" }
|
||||
)
|
||||
|
||||
log:
|
||||
{
|
||||
provider: "syslog"
|
||||
level: "warning"
|
||||
settings:
|
||||
{
|
||||
ident = "webfused"
|
||||
facility = "daemon"
|
||||
log_pid = true
|
||||
}
|
||||
}
|
||||
|
||||
user:
|
||||
{
|
||||
name = "webfused"
|
||||
group = "webfused"
|
||||
}
|
||||
```
|
||||
|
||||
## Version
|
||||
|
||||
The version sections specifies the schema version of the config file.
|
||||
Currently, there is only one schema version defined: 1.0
|
||||
|
||||
## Server
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ------------- | ------ | ------------- | ------------------------ |
|
||||
| vhostname | string | localhost | Name of the virtual host |
|
||||
| port | int | 8080 | Port number of server |
|
||||
| document_root | string | *-empty-* | Path of HTTP files |
|
||||
| tls | object | *-empty-* | see below |
|
||||
|
||||
When *document_root* is omitted, no HTTP files are served.
|
||||
|
||||
### TLS
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | ------------------------------------------- |
|
||||
| certificate | string | *-empty-* | Path to servers own certificate (.pem file) |
|
||||
| key | string | *-empty-* | Path to servers own private key (.pem file) |
|
||||
|
||||
TLS is only activated, when both, *certificate* and *key* are specified.
|
||||
Otherwise, plain websockes without TLS are used.
|
||||
|
||||
## Authentication
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| -------- | ------ | ------------- | ----------------------------------------------- |
|
||||
| provider | string | *-required-* | Name of the authentication provider (see below) |
|
||||
| settings | object | *-empty-* | Provider specific settings (see below)
|
||||
|
||||
Currently, the following providers are supported:
|
||||
|
||||
- *file*: file based authentication
|
||||
- *pam*: authentication based on Linux PAM
|
||||
|
||||
## File Authenticaton Provider
|
||||
|
||||
Allows authentication against a file containing username and password.
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| -------- | ------ | ------------- | ------------------------------- |
|
||||
| file | string | *-required-* | Path to the authentication file |
|
||||
|
||||
## PAM Authenticaton Provider
|
||||
|
||||
Allows authentication using Linux PAM.
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ------------ | ------ | ------------- | ---------------------- |
|
||||
| service_name | string | webfused | PAM service identifier |
|
||||
|
||||
## Filesystems
|
||||
|
||||
Contains a list of file systems that can be provided by webfuse providers.
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | ---------------------------------- |
|
||||
| name | string | *-required-* | Name of the filesystem |
|
||||
| mount_point | string | *-required-* | Local path to mount the filesystem |
|
||||
|
||||
## Log
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | -------------------------------------- |
|
||||
| provider | string | *-required-* | Name of log provider (see below) |
|
||||
| level | string | *-required-* | Log level (see below) |
|
||||
| settings | object | *-empty-* | Provider specific settings (see below) |
|
||||
|
||||
The following log levels are supported:
|
||||
|
||||
- *none*: diabled logging
|
||||
- *fatal*: log only fatal errors
|
||||
- *error*: log all kind of errors
|
||||
- *warn*: log errors and warnings
|
||||
- *info*: log info messages, warnings and errors
|
||||
- *debug*: log debug and info messages as well as warnings and errors
|
||||
- *all*: log all kind of messages
|
||||
|
||||
Currently, the following providers are available:
|
||||
|
||||
- *stderr*: logs to console error output
|
||||
- *syslog*: logs to syslog
|
||||
|
||||
### Stderr Logger
|
||||
|
||||
This logger does not provide any settings.
|
||||
|
||||
### Syslog Logger
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ----------- | ------ | ------------- | ------------------------------------------ |
|
||||
| ident | string | webfused | Syslog ident (see syslog documentation) |
|
||||
| facility | string | daemon | Syslog facility (see syslog documentation) |
|
||||
| log_pid | bool | false | Add process ID to log messages |
|
||||
|
||||
## User
|
||||
|
||||
| Setting | Type | Default value | Description |
|
||||
| ------- | ------ | ------------- | ------------------------------- |
|
||||
| name | string | *-required-* | Name of the user to switch to. |
|
||||
| group | string | *-required-* | Name of the group to switch to. |
|
||||
|
||||
Webfuse daemon will not run as root. If started as root, webfuse daemon tries to
|
||||
switch to *user* and *group* provided in config file.
|
||||
|
||||
*Note*: user and group are not switched, when webfuse daemon is not started as root.
|
@ -173,7 +173,7 @@ static int add_user(struct args * args)
|
||||
}
|
||||
|
||||
struct userdb * db = userdb_create(args->pepper);
|
||||
userdb_load(db, args->file);
|
||||
userdb_load_file(db, args->file);
|
||||
userdb_add(db, args->username, args->password);
|
||||
bool result = userdb_save(db, args->file);
|
||||
userdb_dispose(db);
|
||||
@ -191,7 +191,7 @@ static int remove_user(struct args * args)
|
||||
}
|
||||
|
||||
struct userdb * db = userdb_create(args->pepper);
|
||||
userdb_load(db, args->file);
|
||||
userdb_load_file(db, args->file);
|
||||
userdb_remove(db, args->username);
|
||||
bool result = userdb_save(db, args->file);
|
||||
userdb_dispose(db);
|
||||
@ -216,7 +216,7 @@ static int check_password(struct args * args)
|
||||
}
|
||||
|
||||
struct userdb * db = userdb_create(args->pepper);
|
||||
userdb_load(db, args->file);
|
||||
userdb_load_file(db, args->file);
|
||||
bool result = userdb_check(db, args->username, args->password);
|
||||
userdb_dispose(db);
|
||||
|
||||
|
@ -77,20 +77,17 @@ static char hex_char(unsigned char value)
|
||||
static char * to_hex(unsigned char const * value, size_t length)
|
||||
{
|
||||
char * result = malloc((2 * length) + 1);
|
||||
if (NULL != result)
|
||||
for (size_t i = 0, j = 0; i < length; i++, j+=2)
|
||||
{
|
||||
for (size_t i = 0, j = 0; i < length; i++, j+=2)
|
||||
{
|
||||
unsigned char high = (value[i] >> 4) & 0x0f;
|
||||
unsigned char low = value[i] & 0x0f;
|
||||
unsigned char high = (value[i] >> 4) & 0x0f;
|
||||
unsigned char low = value[i] & 0x0f;
|
||||
|
||||
result[j ] = hex_char(high);
|
||||
result[j + 1] = hex_char(low);
|
||||
}
|
||||
|
||||
result[2 * length] = '\0';
|
||||
result[j ] = hex_char(high);
|
||||
result[j + 1] = hex_char(low);
|
||||
}
|
||||
|
||||
result[2 * length] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -120,21 +117,46 @@ static char * compute_hash(
|
||||
}
|
||||
|
||||
char * result = NULL;
|
||||
EVP_MD_CTX * context = EVP_MD_CTX_new();
|
||||
EVP_DigestInit_ex(context, digest, NULL);
|
||||
EVP_DigestUpdate(context, password, strlen(password));
|
||||
EVP_DigestUpdate(context, salt, strlen(salt));
|
||||
EVP_DigestUpdate(context, db->pepper, strlen(db->pepper));
|
||||
|
||||
unsigned int hash_size = EVP_MD_size(digest);
|
||||
unsigned char * hash = malloc(hash_size);
|
||||
EVP_DigestFinal_ex(context, hash, &hash_size);
|
||||
EVP_MD_CTX_free(context);
|
||||
|
||||
if (NULL != hash)
|
||||
result = to_hex(hash, hash_size);
|
||||
free(hash);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool userdb_load(
|
||||
struct userdb * db,
|
||||
json_t * container)
|
||||
{
|
||||
bool result = false;
|
||||
if (NULL != container)
|
||||
{
|
||||
EVP_MD_CTX * context = EVP_MD_CTX_new();
|
||||
EVP_DigestInit_ex(context, digest, NULL);
|
||||
EVP_DigestUpdate(context, password, strlen(password));
|
||||
EVP_DigestUpdate(context, salt, strlen(salt));
|
||||
EVP_DigestUpdate(context, db->pepper, strlen(db->pepper));
|
||||
EVP_DigestFinal_ex(context, hash, &hash_size);
|
||||
EVP_MD_CTX_free(context);
|
||||
json_t * meta = json_object_get(container, "meta");
|
||||
json_t * users = json_object_get(container, "users");
|
||||
|
||||
result = to_hex(hash, hash_size);
|
||||
free(hash);
|
||||
if ((is_compatible(meta)) && (json_is_object(users))) {
|
||||
json_t * hash_algorithm = json_object_get(meta, "hash_algorithm");
|
||||
free(db->hash_algorithm);
|
||||
db->hash_algorithm = strdup(json_string_value(hash_algorithm));
|
||||
|
||||
json_decref(db->users);
|
||||
json_incref(users);
|
||||
db->users = users;
|
||||
|
||||
result = true;
|
||||
}
|
||||
|
||||
json_decref(container);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -144,12 +166,9 @@ struct userdb * userdb_create(
|
||||
char const * pepper)
|
||||
{
|
||||
struct userdb * db = malloc(sizeof(struct userdb));
|
||||
if (NULL != db)
|
||||
{
|
||||
db->users = json_object();
|
||||
db->pepper = strdup(pepper);
|
||||
db->hash_algorithm = strdup(USERDB_HASH_ALGORITHM);
|
||||
}
|
||||
db->users = json_object();
|
||||
db->pepper = strdup(pepper);
|
||||
db->hash_algorithm = strdup(USERDB_HASH_ALGORITHM);
|
||||
|
||||
return db;
|
||||
}
|
||||
@ -184,36 +203,23 @@ bool userdb_save(
|
||||
return (0 == result);
|
||||
}
|
||||
|
||||
|
||||
bool userdb_load(
|
||||
bool userdb_load_file(
|
||||
struct userdb * db,
|
||||
char const * filename)
|
||||
{
|
||||
bool result = false;
|
||||
json_t * container = json_load_file(filename, 0, NULL);
|
||||
if (NULL != container)
|
||||
{
|
||||
json_t * meta = json_object_get(container, "meta");
|
||||
json_t * users = json_object_get(container, "users");
|
||||
|
||||
if ((is_compatible(meta)) && (json_is_object(users))) {
|
||||
json_t * hash_algorithm = json_object_get(meta, "hash_algorithm");
|
||||
free(db->hash_algorithm);
|
||||
db->hash_algorithm = strdup(json_string_value(hash_algorithm));
|
||||
|
||||
json_decref(db->users);
|
||||
json_incref(users);
|
||||
db->users = users;
|
||||
|
||||
result = true;
|
||||
}
|
||||
|
||||
json_decref(container);
|
||||
}
|
||||
|
||||
return result;
|
||||
return userdb_load(db, container);
|
||||
}
|
||||
|
||||
bool userdb_load_string(
|
||||
struct userdb * db,
|
||||
char const * contents)
|
||||
{
|
||||
json_t * container = json_loads(contents, 0, NULL);
|
||||
return userdb_load(db, container);
|
||||
}
|
||||
|
||||
|
||||
void userdb_add(
|
||||
struct userdb * db,
|
||||
char const * username,
|
||||
@ -243,7 +249,7 @@ static char const * json_object_get_string(
|
||||
json_t * object,
|
||||
char const * key)
|
||||
{
|
||||
char const * result = NULL;
|
||||
char const * result = "";
|
||||
|
||||
json_t * string_holder = json_object_get(object, key);
|
||||
if (json_is_string(string_holder))
|
||||
|
@ -21,10 +21,14 @@ extern bool userdb_save(
|
||||
struct userdb * db,
|
||||
char const * filename);
|
||||
|
||||
extern bool userdb_load(
|
||||
extern bool userdb_load_file(
|
||||
struct userdb * db,
|
||||
char const * filename);
|
||||
|
||||
extern bool userdb_load_string(
|
||||
struct userdb * db,
|
||||
char const * contents);
|
||||
|
||||
extern void userdb_add(
|
||||
struct userdb * db,
|
||||
char const * username,
|
||||
|
@ -37,7 +37,7 @@ wfd_file_authenticator_authenticate(
|
||||
if ((NULL != username) && (NULL != password))
|
||||
{
|
||||
struct userdb * db = userdb_create("");
|
||||
result = userdb_load(db, authenticator->filename);
|
||||
result = userdb_load_file(db, authenticator->filename);
|
||||
if (result)
|
||||
{
|
||||
result = userdb_check(db, username, password);
|
||||
|
@ -94,7 +94,7 @@ wfd_change_user(
|
||||
|
||||
if (is_root)
|
||||
{
|
||||
result = ((NULL != user) || (NULL != group));
|
||||
result = ((NULL != user) && (NULL != group));
|
||||
if (!result)
|
||||
{
|
||||
WFD_ERROR("webfuse daemon cannot be run as root: specify user and group in config");
|
||||
|
@ -71,7 +71,7 @@ wfd_config_read_logger(
|
||||
int rc = config_lookup_string(config, "log.provider", &provider);
|
||||
if (CONFIG_TRUE != rc)
|
||||
{
|
||||
WFD_ERROR("missing log provider");
|
||||
WFD_ERROR("failed to load config: missing log provider");
|
||||
result = false;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ wfd_config_read_logger(
|
||||
rc = config_lookup_string(config, "log.level", &level_str);
|
||||
if (CONFIG_TRUE != rc)
|
||||
{
|
||||
WFD_ERROR("missing log level");
|
||||
WFD_ERROR("failed to load config: missing log level");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
@ -92,7 +92,7 @@ wfd_config_read_logger(
|
||||
bool success = wfd_log_level_parse(level_str, &level);
|
||||
if (!success)
|
||||
{
|
||||
WFD_ERROR("failed to parse log level: unknown valuie \'%s\'", level_str);
|
||||
WFD_ERROR("failed to parse log level: unknown value \'%s\'", level_str);
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
@ -110,7 +110,7 @@ wfd_config_read_logger(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool
|
||||
static void
|
||||
wfd_config_read_server(
|
||||
config_t * config,
|
||||
struct wfd_config * builder)
|
||||
@ -149,8 +149,6 @@ wfd_config_read_server(
|
||||
{
|
||||
wfd_config_set_server_document_root(builder, doc_root);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
@ -159,6 +157,10 @@ wfd_config_read_authenticator(
|
||||
struct wfd_config * builder)
|
||||
{
|
||||
bool result = (NULL != authenticator);
|
||||
if (!result)
|
||||
{
|
||||
WFD_ERROR("failed to load config: invalid authentication section");
|
||||
}
|
||||
|
||||
char const * provider_name = NULL;
|
||||
if (result)
|
||||
@ -166,7 +168,7 @@ wfd_config_read_authenticator(
|
||||
int rc = config_setting_lookup_string(authenticator, "provider", &provider_name);
|
||||
if (CONFIG_TRUE != rc)
|
||||
{
|
||||
WFD_ERROR("missing authentication provider");
|
||||
WFD_ERROR("failed to load config: missing authentication provider");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
@ -177,7 +179,7 @@ wfd_config_read_authenticator(
|
||||
settings = config_setting_lookup(authenticator, "settings");
|
||||
if (NULL == settings)
|
||||
{
|
||||
WFD_ERROR("missing authentication settings");
|
||||
WFD_ERROR("failed to load config: missing authentication settings");
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
@ -312,12 +314,16 @@ wfd_config_load(
|
||||
|
||||
bool success = wfd_config_check_version(config)
|
||||
&& wfd_config_read_logger(config, result)
|
||||
&& wfd_config_read_server(config, result)
|
||||
&& wfd_config_read_authentication(config, result)
|
||||
&& wfd_config_read_filesystems(config, result)
|
||||
&& wfd_config_read_user(config, result)
|
||||
;
|
||||
|
||||
if (success)
|
||||
{
|
||||
wfd_config_read_server(config, result);
|
||||
}
|
||||
|
||||
if (!success)
|
||||
{
|
||||
wfd_config_dispose(result);
|
||||
|
@ -141,10 +141,6 @@ wfd_mountpoint_factory_create_mountpoint(
|
||||
wf_mountpoint_set_userdata(result,
|
||||
&fs->in_use, &wfd_mountpoint_factory_release_mountpoint);
|
||||
|
||||
WFD_INFO("create mountpoint \'%s\' at path \'%s\': %s",
|
||||
filesystem,
|
||||
fs->mount_point,
|
||||
result ? "success" : "failure");
|
||||
|
||||
WFD_INFO("created mountpoint \'%s\' at path \'%s\'", filesystem, fs->mount_point);
|
||||
return result;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "webfused/auth/factory.h"
|
||||
#include "webfused/auth/authenticator.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock_logger.hpp"
|
||||
#include "mock/logger.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::webfused_test::MockLogger;
|
@ -3,8 +3,8 @@
|
||||
#include "webfused/config/settings.h"
|
||||
#include "webfused/auth/factory.h"
|
||||
|
||||
#include "mock_credentials.hpp"
|
||||
#include "mock_settings.hpp"
|
||||
#include "mock/credentials.hpp"
|
||||
#include "mock/settings.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <libconfig.h>
|
||||
@ -13,11 +13,12 @@ using ::webfused_test::MockSettings;
|
||||
using ::webfused_test::MockCredentials;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrEq;
|
||||
using ::testing::_;
|
||||
|
||||
TEST(file_authenticator, create)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -29,7 +30,7 @@ TEST(file_authenticator, create)
|
||||
TEST(file_authenticator, create_fail_missing_file)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
@ -39,7 +40,7 @@ TEST(file_authenticator, create_fail_missing_file)
|
||||
TEST(file_authenticator, create_via_factory)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_authenticator_create("file", nullptr, &authenticator);
|
||||
@ -51,15 +52,15 @@ TEST(file_authenticator, create_via_factory)
|
||||
TEST(file_authenticator, authenticate)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -70,15 +71,15 @@ TEST(file_authenticator, authenticate)
|
||||
TEST(file_authenticator, authenticate_fail_wrong_passwd)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -89,15 +90,15 @@ TEST(file_authenticator, authenticate_fail_wrong_passwd)
|
||||
TEST(file_authenticator, authenticate_fail_no_passwd_file)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("unknown_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("unknown_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secred"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secred"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -108,15 +109,15 @@ TEST(file_authenticator, authenticate_fail_no_passwd_file)
|
||||
TEST(file_authenticator, authenticate_fail_missing_username)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -127,15 +128,15 @@ TEST(file_authenticator, authenticate_fail_missing_username)
|
||||
TEST(file_authenticator, authenticate_fail_missing_password)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("test_passwd.json"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -146,7 +147,7 @@ TEST(file_authenticator, authenticate_fail_missing_password)
|
||||
TEST(file_authenticator, get_type)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_file_authenticator_create(nullptr, &authenticator);
|
@ -3,9 +3,9 @@
|
||||
#include "webfused/config/settings.h"
|
||||
#include "webfused/auth/factory.h"
|
||||
|
||||
#include "mock_credentials.hpp"
|
||||
#include "mock_settings.hpp"
|
||||
#include "mock_pam.hpp"
|
||||
#include "mock/credentials.hpp"
|
||||
#include "mock/settings.hpp"
|
||||
#include "mock/pam.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@ -51,18 +51,18 @@ TEST(pam_authenticator, get_type)
|
||||
TEST(pam_authenticator, authenticate)
|
||||
{
|
||||
MockPam pam;
|
||||
EXPECT_CALL(pam, start(StrEq("webfused"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_start(StrEq("webfused"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_pam_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -73,13 +73,13 @@ TEST(pam_authenticator, authenticate)
|
||||
TEST(pam_authenticator, authenticate_with_custom_service_name)
|
||||
{
|
||||
MockPam pam;
|
||||
EXPECT_CALL(pam, start(StrEq("brummni"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_start(StrEq("brummni"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getStringOrDefault(StrEq("service_name"), StrEq("webfused")))
|
||||
EXPECT_CALL(settings, wfd_settings_get_string_or_default(_,StrEq("service_name"), StrEq("webfused")))
|
||||
.Times(1).WillOnce(Return("brummni"));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
@ -87,8 +87,8 @@ TEST(pam_authenticator, authenticate_with_custom_service_name)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -120,6 +120,8 @@ int valid_conversation(
|
||||
int rc = conv->conv(2, messages, &responses, conv->appdata_ptr);
|
||||
if (PAM_SUCCESS == rc)
|
||||
{
|
||||
free(responses[0].resp);
|
||||
free(responses[1].resp);
|
||||
free(responses);
|
||||
}
|
||||
|
||||
@ -131,19 +133,19 @@ int valid_conversation(
|
||||
TEST(pam_authenticator, conversation_with_valid_messages)
|
||||
{
|
||||
MockPam pam;
|
||||
EXPECT_CALL(pam, start(StrEq("webfused"), nullptr, _, _))
|
||||
EXPECT_CALL(pam, pam_start(StrEq("webfused"), nullptr, _, _))
|
||||
.Times(1).WillOnce(Invoke(&valid_conversation));
|
||||
EXPECT_CALL(pam, authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_pam_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -180,7 +182,7 @@ int invalid_conversation(
|
||||
TEST(pam_authenticator, conversation_with_invalid_messages)
|
||||
{
|
||||
MockPam pam;
|
||||
EXPECT_CALL(pam, start(StrEq("webfused"), nullptr, _, _))
|
||||
EXPECT_CALL(pam, pam_start(StrEq("webfused"), nullptr, _, _))
|
||||
.Times(1).WillOnce(Invoke(&invalid_conversation));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
@ -188,8 +190,8 @@ TEST(pam_authenticator, conversation_with_invalid_messages)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -200,17 +202,17 @@ TEST(pam_authenticator, conversation_with_invalid_messages)
|
||||
TEST(pam_authenticator, authenticate_fail_authenticate)
|
||||
{
|
||||
MockPam pam;
|
||||
EXPECT_CALL(pam, start(StrEq("webfused"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(-1));
|
||||
EXPECT_CALL(pam, end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_start(StrEq("webfused"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(-1));
|
||||
EXPECT_CALL(pam, pam_end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_pam_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -221,18 +223,18 @@ TEST(pam_authenticator, authenticate_fail_authenticate)
|
||||
TEST(pam_authenticator, authenticate_fail_acct_mgmt)
|
||||
{
|
||||
MockPam pam;
|
||||
EXPECT_CALL(pam, start(StrEq("webfused"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(-1));
|
||||
EXPECT_CALL(pam, end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_start(StrEq("webfused"), nullptr, _, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_authenticate(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
EXPECT_CALL(pam, pam_acct_mgmt(_, PAM_DISALLOW_NULL_AUTHTOK)).Times(1).WillOnce(Return(-1));
|
||||
EXPECT_CALL(pam, pam_end(_, _)).Times(1).WillOnce(Return(PAM_SUCCESS));
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool success = wfd_pam_authenticator_create(nullptr, &authenticator);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -249,8 +251,8 @@ TEST(pam_authenticator, authenticate_fail_missing_username)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -267,8 +269,8 @@ TEST(pam_authenticator, authenticate_fail_missing_password)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
154
test/change_user.cc
Normal file
154
test/change_user.cc
Normal file
@ -0,0 +1,154 @@
|
||||
#include "webfused/change_user.h"
|
||||
#include "mock/linux.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using ::webfused_test::MockLinux;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrEq;
|
||||
|
||||
TEST(change_user, nop_id_not_root)
|
||||
{
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(42));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_TRUE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, change_successfully)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 23;
|
||||
|
||||
struct passwd userinfo;
|
||||
userinfo.pw_uid = 42;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
EXPECT_CALL(sys, setgid(23)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, setgroups(0, nullptr)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getpwnam("webfused")).Times(1).WillOnce(Return(&userinfo));
|
||||
EXPECT_CALL(sys, setuid(42)).Times(1).WillOnce(Return(0));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_TRUE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_no_username_or_password)
|
||||
{
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).WillRepeatedly(Return(0));
|
||||
|
||||
ASSERT_FALSE(wfd_change_user(nullptr, "daemons"));
|
||||
ASSERT_FALSE(wfd_change_user("webfused", nullptr));
|
||||
ASSERT_FALSE(wfd_change_user(nullptr, nullptr));
|
||||
}
|
||||
|
||||
TEST(change_user, fail_setuid)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 23;
|
||||
|
||||
struct passwd userinfo;
|
||||
userinfo.pw_uid = 42;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
EXPECT_CALL(sys, setgid(23)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, setgroups(0, nullptr)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getpwnam("webfused")).Times(1).WillOnce(Return(&userinfo));
|
||||
EXPECT_CALL(sys, setuid(42)).Times(1).WillOnce(Return(-1));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_getpwnam)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 23;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
EXPECT_CALL(sys, setgid(23)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, setgroups(0, nullptr)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getpwnam("webfused")).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_setgroups)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 23;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
EXPECT_CALL(sys, setgid(23)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, setgroups(0, nullptr)).Times(1).WillOnce(Return(-1));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_setgid)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 23;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
EXPECT_CALL(sys, setgid(23)).Times(1).WillOnce(Return(-1));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_getgrpnam)
|
||||
{
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_switch_to_root)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 23;
|
||||
|
||||
struct passwd userinfo;
|
||||
userinfo.pw_uid = 0;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
EXPECT_CALL(sys, setgid(23)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, setgroups(0, nullptr)).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getpwnam("webfused")).Times(1).WillOnce(Return(&userinfo));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
||||
|
||||
TEST(change_user, fail_switch_to_root_group)
|
||||
{
|
||||
struct group group;
|
||||
group.gr_gid = 0;
|
||||
|
||||
StrictMock<MockLinux> sys;
|
||||
EXPECT_CALL(sys, getuid).Times(1).WillOnce(Return(0));
|
||||
EXPECT_CALL(sys, getgrnam(StrEq("daemons"))).Times(1).WillOnce(Return(&group));
|
||||
|
||||
bool success = wfd_change_user("webfused", "daemons");
|
||||
ASSERT_FALSE(success);
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfused/config/config.h"
|
||||
#include "webfused/config/config_intern.h"
|
||||
#include "mock_settings.hpp"
|
||||
#include "mock/settings.hpp"
|
||||
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock_logger.hpp"
|
||||
#include "mock/logger.hpp"
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::testing::_;
|
||||
|
||||
@ -36,7 +36,7 @@ TEST(config, auth_config)
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
|
||||
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
|
||||
ASSERT_TRUE(success);
|
||||
@ -50,7 +50,7 @@ TEST(config, auth_config_failed_to_add_second_provider)
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string(_,StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
||||
|
||||
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
|
||||
ASSERT_TRUE(success);
|
74
test/config/configfile.cc
Normal file
74
test/config/configfile.cc
Normal file
@ -0,0 +1,74 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(configfile, is_loadable)
|
||||
{
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_,_,_)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("localhost"))).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_server_port(_,8080)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_)).Times(1).WillOnce(Return(true));
|
||||
|
||||
struct wfd_config * config = wfd_config_load_file("webfused.conf");
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile, minimal_config)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
|
||||
char const minimal[] = "version = { major = 1, minor = 0 }\n";
|
||||
struct wfd_config * config = wfd_config_load_string(minimal);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile, invalid_config)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(0);
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
|
||||
|
||||
char const syntax_error[] = "version.major = 1\n";
|
||||
|
||||
wfd_config * config = wfd_config_load_string(syntax_error);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile, invalid_config_file)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(0);
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
|
||||
|
||||
struct wfd_config * config = wfd_config_load_file("invalid.conf");
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
138
test/config/configfile_auth.cc
Normal file
138
test/config/configfile_auth.cc
Normal file
@ -0,0 +1,138 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(config_auth, authentication)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config_auth, failed_create_authenticator)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config_auth, failed_missing_auth_provider)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config_auth, failed_missing_auth_settings)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config_auth, failed_auth_settings_get_elem)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
MockLibConfig libconfig;
|
||||
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
148
test/config/configfile_filesystem.cc
Normal file
148
test/config/configfile_filesystem.cc
Normal file
@ -0,0 +1,148 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(configfile_fs, filesystems)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(true));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_fs, filesystems_empty)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_fs, filesystems_failed_add)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(false));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_fs, filesystems_failed_missing_name)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_fs, filesystems_failed_missing_mountpoint)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\"}\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_fs, filesystems_failed_missing_elem)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
||||
|
||||
MockLibConfig libconfig;
|
||||
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
128
test/config/configfile_log.cc
Normal file
128
test/config/configfile_log.cc
Normal file
@ -0,0 +1,128 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(configfile_log, set_logger)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(true));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
" level = \"all\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_log, log_fail_set_logger)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
" level = \"all\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_log, log_fail_missing_provider)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" level = \"all\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_log, log_fail_missing_level)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
" level = \"fancy\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_log, log_fail_invalid_level)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
127
test/config/configfile_server.cc
Normal file
127
test/config/configfile_server.cc
Normal file
@ -0,0 +1,127 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(configfile_server, vhost_name)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("some.host"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" vhost_name = \"some.host\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_server, port)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_server_port(_,54321)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" port = 54321\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_server, tls_certificate)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_server_cert(_, StrEq("/path/to/cert.pem"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" tls:\n"
|
||||
" {\n"
|
||||
" certificate = \"/path/to/cert.pem\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_server, tls_key)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_server_key(_,StrEq("/path/to/key.pem"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" tls:\n"
|
||||
" {\n"
|
||||
" key = \"/path/to/key.pem\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_server, document_root)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_server_document_root(_,StrEq("/var/www"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" document_root = \"/var/www\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
82
test/config/configfile_user.cc
Normal file
82
test/config/configfile_user.cc
Normal file
@ -0,0 +1,82 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(configfile_user, set_user)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"user:\n"
|
||||
"{\n"
|
||||
" name = \"webfused\"\n"
|
||||
" group = \"webfused\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_user, set_user_fail_missing_name)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"user:\n"
|
||||
"{\n"
|
||||
" group = \"webfused\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_user, set_user_fail_missing_group)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"user:\n"
|
||||
"{\n"
|
||||
" name = \"webfused\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
110
test/config/configfile_version.cc
Normal file
110
test/config/configfile_version.cc
Normal file
@ -0,0 +1,110 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock/logger.hpp"
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "mock/libconfig.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
using ::webfused_test::MockLibConfig;
|
||||
|
||||
TEST(configfile_version, invalid_major_version_too_low)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
char const too_low[] = "version = { major = 0, minor = 0 }\n";
|
||||
|
||||
struct wfd_config * config= wfd_config_load_string(too_low);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_version, invalid_major_version_too_high)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
char const too_high[] = "version = { major = 2, minor = 0 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_version, invalid_missing_major_version)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
char const too_high[] = "version = { minor = 0 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_version, invalid_missing_minor_version)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||
|
||||
char const too_high[] = "version = { major = 1 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_version, valid_older_minor)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
|
||||
char const valid[] = "version = { major = 1, minor = -1 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(valid);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(configfile_version, valid_newer_minor)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
|
||||
char const valid[] = "version = { major = 1, minor = 1 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(valid);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
#include "webfused/daemon.h"
|
||||
|
||||
#include "mock/server.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cstdlib>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
using ::webfused_test::MockServer;
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
|
||||
TEST(daemon, print_usage)
|
||||
{
|
||||
char argv0[] = "daemon";
|
||||
@ -66,3 +72,17 @@ TEST(daemon, run)
|
||||
|
||||
thread.join();
|
||||
}
|
||||
|
||||
TEST(daemon, run_failed_to_create_server)
|
||||
{
|
||||
MockServer server;
|
||||
EXPECT_CALL(server, wf_server_create(_)).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
char argv0[] = "daemon";
|
||||
char argv1[] = "-f";
|
||||
char argv2[] = "webfused.conf";
|
||||
char * argv[] = { argv0, argv1, argv2, NULL};
|
||||
|
||||
int exit_code = wfd_daemon_run(3, argv);
|
||||
ASSERT_EQ(EXIT_FAILURE, exit_code);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock_logger.hpp"
|
||||
#include "mock/logger.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::StrEq;
|
@ -3,7 +3,7 @@
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
|
||||
#include "mock_settings.hpp"
|
||||
#include "mock/settings.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <stddef.h>
|
||||
@ -22,9 +22,9 @@ TEST(syslog_logger, init)
|
||||
TEST(syslog_logger, init_fail_invalid_facility)
|
||||
{
|
||||
MockSettings settings;
|
||||
EXPECT_CALL(settings, getStringOrDefault(StrEq("ident"), _)).Times(1).WillOnce(Return("webfused_test"));
|
||||
EXPECT_CALL(settings, getStringOrDefault(StrEq("facility"), _)).Times(1).WillOnce(Return("invalid"));
|
||||
EXPECT_CALL(settings, getBool(StrEq("log_pid"))).Times(1).WillOnce(Return(false));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string_or_default(_,StrEq("ident"), _)).Times(1).WillOnce(Return("webfused_test"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_string_or_default(_,StrEq("facility"), _)).Times(1).WillOnce(Return("invalid"));
|
||||
EXPECT_CALL(settings, wfd_settings_get_bool(_,StrEq("log_pid"))).Times(1).WillOnce(Return(false));
|
||||
|
||||
wfd_settings * fake_settings = reinterpret_cast<wfd_settings*>(0xDEADBEEF);
|
||||
ASSERT_FALSE(wfd_syslog_logger_init(WFD_LOGLEVEL_ALL, fake_settings));
|
40
test/mock/config_builder.cc
Normal file
40
test/mock/config_builder.cc
Normal file
@ -0,0 +1,40 @@
|
||||
#include "mock/config_builder.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfused_test::IConfigBuilder * wfd_MockConfigBuilder = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC0(wfd_MockConfigBuilder, wfd_config *, wfd_config_create);
|
||||
WFD_WRAP_FUNC1(wfd_MockConfigBuilder, void, wfd_config_dispose, wfd_config *);
|
||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_vhostname, wfd_config *, char const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_port, wfd_config *, int);
|
||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_key, wfd_config *, char const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_cert, wfd_config *, char const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_document_root, wfd_config *, char const *);
|
||||
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, bool, wfd_config_add_auth_provider, wfd_config *, char const *, wfd_settings *);
|
||||
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, bool, wfd_config_add_filesystem, wfd_config *, char const *, char const *);
|
||||
WFD_WRAP_FUNC4(wfd_MockConfigBuilder, bool, wfd_config_set_logger, wfd_config *, char const *, int, wfd_settings *);
|
||||
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, void, wfd_config_set_user, wfd_config *, char const *, char const *);
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockConfigBuilder::MockConfigBuilder()
|
||||
{
|
||||
wfd_MockConfigBuilder = this;
|
||||
}
|
||||
|
||||
MockConfigBuilder::~MockConfigBuilder()
|
||||
{
|
||||
wfd_MockConfigBuilder = nullptr;
|
||||
}
|
||||
|
||||
struct wfd_config * MockConfigBuilder::getBuilder()
|
||||
{
|
||||
IConfigBuilder * config_builder = this;
|
||||
|
||||
return reinterpret_cast<wfd_config *>(config_builder);
|
||||
}
|
||||
}
|
49
test/mock/config_builder.hpp
Normal file
49
test/mock/config_builder.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef WFD_MOCK_CONFIG_BUILDER_HPP
|
||||
#define WFD_MOCK_CONFIG_BUILDER_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfused/config/config_intern.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IConfigBuilder
|
||||
{
|
||||
public:
|
||||
virtual ~IConfigBuilder() = default;
|
||||
virtual wfd_config * wfd_config_create(void) = 0;
|
||||
virtual void wfd_config_dispose(wfd_config * config) = 0;
|
||||
virtual void wfd_config_set_server_vhostname(wfd_config * config, char const * vhostname) = 0;
|
||||
virtual void wfd_config_set_server_port(wfd_config * config, int port) = 0;
|
||||
virtual void wfd_config_set_server_key(wfd_config * config, char const * key_path) = 0;
|
||||
virtual void wfd_config_set_server_cert(wfd_config * config, char const * cert_path) = 0;
|
||||
virtual void wfd_config_set_server_document_root(wfd_config * config, char const * document_root) = 0;
|
||||
virtual bool wfd_config_add_auth_provider(wfd_config * config, char const * provider, wfd_settings * settings) = 0;
|
||||
virtual bool wfd_config_add_filesystem(wfd_config * config, char const * name, char const * mountpoint) = 0;
|
||||
virtual bool wfd_config_set_logger(wfd_config * config, char const * provider, int level, wfd_settings * settings) = 0;
|
||||
virtual void wfd_config_set_user(wfd_config * config, char const * user, char const * group) = 0;
|
||||
};
|
||||
|
||||
class MockConfigBuilder: public IConfigBuilder
|
||||
{
|
||||
public:
|
||||
MockConfigBuilder();
|
||||
~MockConfigBuilder() override;
|
||||
MOCK_METHOD0(wfd_config_create, wfd_config * (void));
|
||||
MOCK_METHOD1(wfd_config_dispose, void (wfd_config * config));
|
||||
MOCK_METHOD2(wfd_config_set_server_vhostname, void (wfd_config * config, char const * vhostname));
|
||||
MOCK_METHOD2(wfd_config_set_server_port, void (wfd_config * config, int port));
|
||||
MOCK_METHOD2(wfd_config_set_server_key, void (wfd_config * config, char const * key_path));
|
||||
MOCK_METHOD2(wfd_config_set_server_cert, void (wfd_config * config, char const * cert_path));
|
||||
MOCK_METHOD2(wfd_config_set_server_document_root, void (wfd_config * config, char const * document_root));
|
||||
MOCK_METHOD3(wfd_config_add_auth_provider, bool (wfd_config * config, char const * provider, wfd_settings * settings));
|
||||
MOCK_METHOD3(wfd_config_add_filesystem, bool (wfd_config * config, char const * name, char const * mountpoint));
|
||||
MOCK_METHOD4(wfd_config_set_logger, bool (wfd_config * config, char const * provider, int level, wfd_settings * settings));
|
||||
MOCK_METHOD3(wfd_config_set_user, void (wfd_config * config, char const * user, char const * group));
|
||||
|
||||
struct wfd_config * getBuilder();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
26
test/mock/credentials.cc
Normal file
26
test/mock/credentials.cc
Normal file
@ -0,0 +1,26 @@
|
||||
#include "mock/credentials.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfused_test::ICredentials * wfd_MockCredentials = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC1(wfd_MockCredentials, char const *, wf_credentials_type, struct wf_credentials const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockCredentials, char const *, wf_credentials_get, struct wf_credentials const *, char const *);
|
||||
}
|
||||
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockCredentials::MockCredentials()
|
||||
{
|
||||
wfd_MockCredentials = this;
|
||||
}
|
||||
|
||||
MockCredentials::~MockCredentials()
|
||||
{
|
||||
wfd_MockCredentials = nullptr;
|
||||
}
|
||||
|
||||
}
|
29
test/mock/credentials.hpp
Normal file
29
test/mock/credentials.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef WFD_MOCK_CREDENTIALS_HPP
|
||||
#define WFD_MOCK_CREDENTIALS_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfuse/adapter/credentials.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ICredentials
|
||||
{
|
||||
public:
|
||||
virtual ~ICredentials() = default;
|
||||
virtual char const * wf_credentials_type(struct wf_credentials const * credentials) = 0;
|
||||
virtual char const * wf_credentials_get(struct wf_credentials const * credentials, char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockCredentials: public ICredentials
|
||||
{
|
||||
public:
|
||||
MockCredentials();
|
||||
virtual ~MockCredentials();
|
||||
MOCK_METHOD1(wf_credentials_type, char const*(struct wf_credentials const * credentials));
|
||||
MOCK_METHOD2(wf_credentials_get, char const *(struct wf_credentials const * credentials, char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
27
test/mock/libconfig.cc
Normal file
27
test/mock/libconfig.cc
Normal file
@ -0,0 +1,27 @@
|
||||
#include "mock/libconfig.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
static webfused_test::ILibConfig * wfd_MockLibConfig = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC2(wfd_MockLibConfig, config_setting_t *, config_setting_get_elem,
|
||||
config_setting_t const *, unsigned int);
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockLibConfig::MockLibConfig()
|
||||
{
|
||||
wfd_MockLibConfig = this;
|
||||
}
|
||||
|
||||
MockLibConfig::~MockLibConfig()
|
||||
{
|
||||
wfd_MockLibConfig = nullptr;
|
||||
}
|
||||
|
||||
}
|
32
test/mock/libconfig.hpp
Normal file
32
test/mock/libconfig.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef WFD_MOCK_LIBCONFIG_HPP
|
||||
#define WFD_MOCK_LIBCONFIG_HPP
|
||||
|
||||
#include <libconfig.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ILibConfig
|
||||
{
|
||||
public:
|
||||
virtual ~ILibConfig() = default;
|
||||
virtual config_setting_t * config_setting_get_elem(
|
||||
config_setting_t const * setting,
|
||||
unsigned int i) = 0;
|
||||
};
|
||||
|
||||
class MockLibConfig: public ILibConfig
|
||||
{
|
||||
public:
|
||||
MockLibConfig();
|
||||
~MockLibConfig() override;
|
||||
MOCK_METHOD2(config_setting_get_elem, config_setting_t * (
|
||||
config_setting_t const * setting,
|
||||
unsigned int i));
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
31
test/mock/linux.cc
Normal file
31
test/mock/linux.cc
Normal file
@ -0,0 +1,31 @@
|
||||
#include "mock/linux.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
static webfused_test::ILinux * wfd_MockLinux = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC0( wfd_MockLinux, uid_t, getuid);
|
||||
WFD_WRAP_FUNC1( wfd_MockLinux, struct group *, getgrnam, char const *);
|
||||
WFD_WRAP_FUNC1( wfd_MockLinux, int, setgid, gid_t);
|
||||
WFD_WRAP_FUNC2( wfd_MockLinux, int, setgroups, int, gid_t *);
|
||||
WFD_WRAP_FUNC1( wfd_MockLinux, struct passwd *, getpwnam, char const *);
|
||||
WFD_WRAP_FUNC1( wfd_MockLinux, int, setuid, uid_t);
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockLinux::MockLinux()
|
||||
{
|
||||
wfd_MockLinux = this;
|
||||
}
|
||||
|
||||
MockLinux::~MockLinux()
|
||||
{
|
||||
wfd_MockLinux = nullptr;
|
||||
}
|
||||
|
||||
}
|
41
test/mock/linux.hpp
Normal file
41
test/mock/linux.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef WFD_MOCK_LINUX_HPP
|
||||
#define WFD_MOCK_LINUX_HPP
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ILinux
|
||||
{
|
||||
public:
|
||||
virtual ~ILinux() = default;
|
||||
virtual uid_t getuid() = 0;
|
||||
virtual struct group * getgrnam(char const * name) = 0;
|
||||
virtual int setgid(gid_t gid) = 0;
|
||||
virtual int setgroups(int size, gid_t * list) = 0;
|
||||
virtual struct passwd * getpwnam(char const * name) = 0;
|
||||
virtual int setuid(uid_t uid) = 0;
|
||||
};
|
||||
|
||||
class MockLinux: public ILinux
|
||||
{
|
||||
public:
|
||||
MockLinux();
|
||||
~MockLinux();
|
||||
MOCK_METHOD0(getuid, uid_t());
|
||||
MOCK_METHOD1(getgrnam, struct group * (char const * name));
|
||||
MOCK_METHOD1(setgid, int (gid_t gid));
|
||||
MOCK_METHOD2(setgroups, int (int size, gid_t * list));
|
||||
MOCK_METHOD1(getpwnam, struct passwd * (char const * name));
|
||||
MOCK_METHOD1(setuid, int (uid_t uid));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
#include "mock_logger.hpp"
|
||||
#include "mock/logger.hpp"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
|
29
test/mock/pam.cc
Normal file
29
test/mock/pam.cc
Normal file
@ -0,0 +1,29 @@
|
||||
#include "mock/pam.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfused_test::IPam * wfd_MockPam = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC4(wfd_MockPam, int, pam_start, char const *, char const *, struct pam_conv const *, pam_handle_t **);
|
||||
WFD_WRAP_FUNC2(wfd_MockPam, int, pam_end, pam_handle_t *, int);
|
||||
WFD_WRAP_FUNC2(wfd_MockPam, int, pam_authenticate, pam_handle_t *, int);
|
||||
WFD_WRAP_FUNC2(wfd_MockPam, int, pam_acct_mgmt, pam_handle_t *, int);
|
||||
WFD_WRAP_FUNC2(wfd_MockPam, char const *, pam_strerror, pam_handle_t *, int);
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockPam::MockPam()
|
||||
{
|
||||
wfd_MockPam = this;
|
||||
}
|
||||
|
||||
MockPam::~MockPam()
|
||||
{
|
||||
wfd_MockPam = nullptr;
|
||||
}
|
||||
|
||||
}
|
45
test/mock/pam.hpp
Normal file
45
test/mock/pam.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef WFD_MOCK_PAM_HPP
|
||||
#define WFD_MOCK_PAM_HPP
|
||||
|
||||
#include <security/pam_appl.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IPam
|
||||
{
|
||||
public:
|
||||
virtual ~IPam() = default;
|
||||
virtual int pam_start(
|
||||
char const * service_name,
|
||||
char const * user,
|
||||
struct pam_conv const * conversation,
|
||||
pam_handle_t * * handle) = 0;
|
||||
virtual int pam_end(pam_handle_t * handle, int status) = 0;
|
||||
virtual int pam_authenticate(pam_handle_t * handle, int flags) = 0;
|
||||
virtual int pam_acct_mgmt(pam_handle_t * handle, int flags) = 0;
|
||||
virtual char const * pam_strerror(pam_handle_t * handle, int errnum) = 0;
|
||||
};
|
||||
|
||||
class MockPam: public IPam
|
||||
{
|
||||
public:
|
||||
MockPam();
|
||||
~MockPam() override;
|
||||
|
||||
MOCK_METHOD4(pam_start, int (
|
||||
char const * service_name,
|
||||
char const * user,
|
||||
struct pam_conv const * conversation,
|
||||
pam_handle_t * * handle));
|
||||
|
||||
MOCK_METHOD2(pam_end, int(pam_handle_t * handle, int status));
|
||||
MOCK_METHOD2(pam_authenticate, int(pam_handle_t * handle, int flags));
|
||||
MOCK_METHOD2(pam_acct_mgmt, int (pam_handle_t * handle, int flags));
|
||||
MOCK_METHOD2(pam_strerror, char const * (pam_handle_t * handle, int errnum));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
25
test/mock/server.cc
Normal file
25
test/mock/server.cc
Normal file
@ -0,0 +1,25 @@
|
||||
#include "mock/server.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfused_test::IServer * wfd_MockServer = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC1(wfd_MockServer, struct wf_server *, wf_server_create, struct wf_server_config *);
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockServer::MockServer()
|
||||
{
|
||||
wfd_MockServer = this;
|
||||
}
|
||||
|
||||
MockServer::~MockServer()
|
||||
{
|
||||
wfd_MockServer = nullptr;
|
||||
}
|
||||
|
||||
}
|
28
test/mock/server.hpp
Normal file
28
test/mock/server.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef WFD_MOCK_SERVER_HPP
|
||||
#define WFD_MOCK_SERVER_HPP
|
||||
|
||||
#include <webfuse/adapter/server.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IServer
|
||||
{
|
||||
public:
|
||||
virtual ~IServer() = default;
|
||||
virtual struct wf_server * wf_server_create(struct wf_server_config * config) = 0;
|
||||
};
|
||||
|
||||
class MockServer: public IServer
|
||||
{
|
||||
public:
|
||||
MockServer();
|
||||
~MockServer() override;
|
||||
MOCK_METHOD1(wf_server_create, struct wf_server * (struct wf_server_config * config));
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
27
test/mock/settings.cc
Normal file
27
test/mock/settings.cc
Normal file
@ -0,0 +1,27 @@
|
||||
#include "mock/settings.hpp"
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfused_test::ISettings * wfd_MockSettings = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC2(wfd_MockSettings, char const *, wfd_settings_get_string, struct wfd_settings *, char const *);
|
||||
WFD_WRAP_FUNC3(wfd_MockSettings, char const *, wfd_settings_get_string_or_default,
|
||||
struct wfd_settings *, char const *, char const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockSettings, bool, wfd_settings_get_bool, struct wfd_settings *, char const *);
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockSettings::MockSettings()
|
||||
{
|
||||
wfd_MockSettings = this;
|
||||
}
|
||||
|
||||
MockSettings::~MockSettings()
|
||||
{
|
||||
wfd_MockSettings = nullptr;
|
||||
}
|
||||
|
||||
}
|
33
test/mock/settings.hpp
Normal file
33
test/mock/settings.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
#define WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfused/config/settings.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ISettings
|
||||
{
|
||||
public:
|
||||
virtual ~ISettings() = default;
|
||||
virtual char const * wfd_settings_get_string(wfd_settings * settings, char const * key) = 0;
|
||||
virtual char const * wfd_settings_get_string_or_default(wfd_settings * settings, char const * key, char const * default_value) = 0;
|
||||
virtual bool wfd_settings_get_bool(wfd_settings * settings, char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockSettings: public ISettings
|
||||
{
|
||||
public:
|
||||
MockSettings();
|
||||
~MockSettings() override;
|
||||
MOCK_METHOD2(wfd_settings_get_string, char const * (wfd_settings * settings, char const * key));
|
||||
MOCK_METHOD3(wfd_settings_get_string_or_default, char const * (wfd_settings * settings, char const * key, char const * default_value));
|
||||
MOCK_METHOD2(wfd_settings_get_bool, bool (wfd_settings * settings, char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,254 +0,0 @@
|
||||
#include "mock_config_builder.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::IConfigBuilder;
|
||||
|
||||
static IConfigBuilder * wfd_MockConfigBuilder = nullptr;
|
||||
|
||||
extern struct wfd_config *
|
||||
__real_wfd_config_create(void);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_dispose(
|
||||
struct wfd_config * config);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_set_server_vhostname(
|
||||
struct wfd_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_set_server_port(
|
||||
struct wfd_config * config,
|
||||
int port);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_set_server_key(
|
||||
struct wfd_config * config,
|
||||
char const * key_path);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_set_server_cert(
|
||||
struct wfd_config * config,
|
||||
char const * cert_path);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_set_server_document_root(
|
||||
struct wfd_config * config,
|
||||
char const * document_root);
|
||||
|
||||
extern bool
|
||||
__real_wfd_config_add_auth_provider(
|
||||
struct wfd_config * config,
|
||||
char const * provider,
|
||||
struct wfd_settings * settings);
|
||||
|
||||
extern bool
|
||||
__real_wfd_config_add_filesystem(
|
||||
struct wfd_config * config,
|
||||
char const * name,
|
||||
char const * mount_point);
|
||||
|
||||
extern bool
|
||||
__real_wfd_config_set_logger(
|
||||
struct wfd_config * config,
|
||||
char const * provider,
|
||||
int level,
|
||||
struct wfd_settings * settings);
|
||||
|
||||
extern void
|
||||
__real_wfd_config_set_user(
|
||||
struct wfd_config * config,
|
||||
char const * user,
|
||||
char const * group);
|
||||
|
||||
struct wfd_config *
|
||||
__wrap_wfd_config_create(void)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
return __real_wfd_config_create();
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockConfigBuilder->create();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_dispose(
|
||||
struct wfd_config * config)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_dispose(config);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->dispose(config);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_set_server_vhostname(
|
||||
struct wfd_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_set_server_vhostname(config, vhost_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->setServerVhostname(vhost_name);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_set_server_port(
|
||||
struct wfd_config * config,
|
||||
int port)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_set_server_port(config, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->setServerPort(port);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_set_server_key(
|
||||
struct wfd_config * config,
|
||||
char const * key_path)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_set_server_key(config, key_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->setServerKey(key_path);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_set_server_cert(
|
||||
struct wfd_config * config,
|
||||
char const * cert_path)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_set_server_cert(config, cert_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->setServerCert(cert_path);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_set_server_document_root(
|
||||
struct wfd_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_set_server_document_root(config, document_root);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->setServerDocumentRoot(document_root);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
__wrap_wfd_config_add_auth_provider(
|
||||
struct wfd_config * config,
|
||||
char const * provider,
|
||||
struct wfd_settings * settings)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
return __real_wfd_config_add_auth_provider(config, provider, settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockConfigBuilder->addAuthProvider(provider, settings);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
__wrap_wfd_config_add_filesystem(
|
||||
struct wfd_config * config,
|
||||
char const * name,
|
||||
char const * mount_point)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
return __real_wfd_config_add_filesystem(config, name, mount_point);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockConfigBuilder->addFilesystem(name, mount_point);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
__wrap_wfd_config_set_logger(
|
||||
struct wfd_config * config,
|
||||
char const * provider,
|
||||
int level,
|
||||
struct wfd_settings * settings)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
return __real_wfd_config_set_logger(config, provider, level, settings);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockConfigBuilder->setLogger(provider, level, settings);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
__wrap_wfd_config_set_user(
|
||||
struct wfd_config * config,
|
||||
char const * user,
|
||||
char const * group)
|
||||
{
|
||||
if (nullptr == wfd_MockConfigBuilder)
|
||||
{
|
||||
__real_wfd_config_set_user(config, user, group);
|
||||
}
|
||||
else
|
||||
{
|
||||
wfd_MockConfigBuilder->setUser(user, group);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockConfigBuilder::MockConfigBuilder()
|
||||
{
|
||||
wfd_MockConfigBuilder = this;
|
||||
}
|
||||
|
||||
MockConfigBuilder::~MockConfigBuilder()
|
||||
{
|
||||
wfd_MockConfigBuilder = nullptr;
|
||||
}
|
||||
|
||||
struct wfd_config * MockConfigBuilder::getBuilder()
|
||||
{
|
||||
IConfigBuilder * config_builder = this;
|
||||
|
||||
return reinterpret_cast<wfd_config *>(config_builder);
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
#ifndef WFD_MOCK_CONFIG_BUILDER_HPP
|
||||
#define WFD_MOCK_CONFIG_BUILDER_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfused/config/config_intern.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IConfigBuilder
|
||||
{
|
||||
public:
|
||||
virtual ~IConfigBuilder() = default;
|
||||
virtual wfd_config * create(void) = 0;
|
||||
virtual void dispose(wfd_config * config) = 0;
|
||||
virtual void setServerVhostname(char const * vhostname) = 0;
|
||||
virtual void setServerPort(int port) = 0;
|
||||
virtual void setServerKey(char const * key_path) = 0;
|
||||
virtual void setServerCert(char const * cert_path) = 0;
|
||||
virtual void setServerDocumentRoot(char const * document_root) = 0;
|
||||
virtual bool addAuthProvider(char const * provider, wfd_settings * settings) = 0;
|
||||
virtual bool addFilesystem(char const * name, char const * mountpoint) = 0;
|
||||
virtual bool setLogger(char const * provider, int level, wfd_settings * settings) = 0;
|
||||
virtual void setUser(char const * user, char const * group) = 0;
|
||||
};
|
||||
|
||||
class MockConfigBuilder: public IConfigBuilder
|
||||
{
|
||||
public:
|
||||
MockConfigBuilder();
|
||||
~MockConfigBuilder() override;
|
||||
MOCK_METHOD0(create, wfd_config * (void));
|
||||
MOCK_METHOD1(dispose, void (wfd_config * config));
|
||||
MOCK_METHOD1(setServerVhostname, void (char const * vhostname));
|
||||
MOCK_METHOD1(setServerPort, void (int port));
|
||||
MOCK_METHOD1(setServerKey, void (char const * key_path));
|
||||
MOCK_METHOD1(setServerCert, void (char const * cert_path));
|
||||
MOCK_METHOD1(setServerDocumentRoot, void (char const * document_root));
|
||||
MOCK_METHOD2(addAuthProvider, bool (char const * provider, wfd_settings * settings));
|
||||
MOCK_METHOD2(addFilesystem, bool (char const * name, char const * mountpoint));
|
||||
MOCK_METHOD3(setLogger, bool (char const * provider, int level, wfd_settings * settings));
|
||||
MOCK_METHOD2(setUser, void (char const * user, char const * group));
|
||||
|
||||
struct wfd_config * getBuilder();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,64 +0,0 @@
|
||||
#include "mock_credentials.hpp"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::ICredentials;
|
||||
|
||||
static ICredentials * wfd_mock_credentials = nullptr;
|
||||
|
||||
extern char const *
|
||||
__real_wf_credentials_type(
|
||||
struct wf_credentials const * credentials);
|
||||
|
||||
char const *
|
||||
__wrap_wf_credentials_type(
|
||||
struct wf_credentials const * credentials)
|
||||
{
|
||||
if (nullptr == wfd_mock_credentials)
|
||||
{
|
||||
return __real_wf_credentials_type(credentials);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_credentials->type();
|
||||
}
|
||||
}
|
||||
|
||||
extern char const * __real_wf_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
|
||||
char const * __wrap_wf_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_credentials)
|
||||
{
|
||||
return __real_wf_credentials_get(credentials, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_credentials->get(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockCredentials::MockCredentials()
|
||||
{
|
||||
wfd_mock_credentials = this;
|
||||
}
|
||||
|
||||
MockCredentials::~MockCredentials()
|
||||
{
|
||||
wfd_mock_credentials = nullptr;
|
||||
}
|
||||
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
#ifndef WFD_MOCK_CREDENTIALS_HPP
|
||||
#define WFD_MOCK_CREDENTIALS_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfuse/adapter/credentials.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ICredentials
|
||||
{
|
||||
public:
|
||||
virtual ~ICredentials() = default;
|
||||
virtual char const * type() = 0;
|
||||
virtual char const * get(char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockCredentials: public ICredentials
|
||||
{
|
||||
public:
|
||||
MockCredentials();
|
||||
virtual ~MockCredentials();
|
||||
MOCK_METHOD0(type, char const*());
|
||||
MOCK_METHOD1(get, char const *(char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,99 +0,0 @@
|
||||
#include "mock_pam.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
static webfused_test::IPam * wfd_MockPam = nullptr;
|
||||
|
||||
extern int __real_pam_start(
|
||||
char const * service_name,
|
||||
char const * user,
|
||||
struct pam_conv const * conversation,
|
||||
pam_handle_t * * handle);
|
||||
extern int __real_pam_end(pam_handle_t * handle, int status);
|
||||
extern int __real_pam_authenticate(pam_handle_t * handle, int flags);
|
||||
extern int __real_pam_acct_mgmt(pam_handle_t * handle, int flags);
|
||||
extern char const * __real_pam_strerror(pam_handle_t * handle, int errnum);
|
||||
|
||||
int __wrap_pam_start(
|
||||
char const * service_name,
|
||||
char const * user,
|
||||
struct pam_conv const * conversation,
|
||||
pam_handle_t * * handle)
|
||||
{
|
||||
if (nullptr == wfd_MockPam)
|
||||
{
|
||||
return __real_pam_start(service_name, user, conversation, handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockPam->start(service_name, user, conversation, handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int __wrap_pam_end(pam_handle_t * handle, int status)
|
||||
{
|
||||
if (nullptr == wfd_MockPam)
|
||||
{
|
||||
return __real_pam_end(handle, status);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockPam->end(handle, status);
|
||||
}
|
||||
}
|
||||
|
||||
int __wrap_pam_authenticate(pam_handle_t * handle, int flags)
|
||||
{
|
||||
if (nullptr == wfd_MockPam)
|
||||
{
|
||||
return __real_pam_authenticate(handle, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockPam->authenticate(handle, flags);
|
||||
}
|
||||
}
|
||||
|
||||
int __wrap_pam_acct_mgmt(pam_handle_t * handle, int flags)
|
||||
{
|
||||
if (nullptr == wfd_MockPam)
|
||||
{
|
||||
return __real_pam_acct_mgmt(handle, flags);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockPam->acct_mgmt(handle, flags);
|
||||
}
|
||||
}
|
||||
|
||||
char const * __wrap_pam_strerror(pam_handle_t * handle, int errnum)
|
||||
{
|
||||
if (nullptr == wfd_MockPam)
|
||||
{
|
||||
return __real_pam_strerror(handle, errnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_MockPam->strerror(handle, errnum);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockPam::MockPam()
|
||||
{
|
||||
wfd_MockPam = this;
|
||||
}
|
||||
|
||||
MockPam::~MockPam()
|
||||
{
|
||||
wfd_MockPam = nullptr;
|
||||
}
|
||||
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
#ifndef WFD_MOCK_PAM_HPP
|
||||
#define WFD_MOCK_PAM_HPP
|
||||
|
||||
#include <security/pam_appl.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class IPam
|
||||
{
|
||||
public:
|
||||
virtual ~IPam() = default;
|
||||
virtual int start(
|
||||
char const * service_name,
|
||||
char const * user,
|
||||
struct pam_conv const * conversation,
|
||||
pam_handle_t * * handle) = 0;
|
||||
virtual int end(pam_handle_t * handle, int status) = 0;
|
||||
virtual int authenticate(pam_handle_t * handle, int flags) = 0;
|
||||
virtual int acct_mgmt(pam_handle_t * handle, int flags) = 0;
|
||||
virtual char const * strerror(pam_handle_t * handle, int errnum) = 0;
|
||||
};
|
||||
|
||||
class MockPam: public IPam
|
||||
{
|
||||
public:
|
||||
MockPam();
|
||||
~MockPam() override;
|
||||
|
||||
MOCK_METHOD4(start, int (
|
||||
char const * service_name,
|
||||
char const * user,
|
||||
struct pam_conv const * conversation,
|
||||
pam_handle_t * * handle));
|
||||
|
||||
MOCK_METHOD2(end, int(pam_handle_t * handle, int status));
|
||||
MOCK_METHOD2(authenticate, int(pam_handle_t * handle, int flags));
|
||||
MOCK_METHOD2(acct_mgmt, int (pam_handle_t * handle, int flags));
|
||||
MOCK_METHOD2(strerror, char const * (pam_handle_t * handle, int errnum));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,87 +0,0 @@
|
||||
#include "mock_settings.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::ISettings;
|
||||
|
||||
static ISettings * wfd_mock_settings = nullptr;
|
||||
|
||||
extern char const *
|
||||
__real_wfd_settings_get_string(
|
||||
struct wfd_settings * settings,
|
||||
char const * key);
|
||||
|
||||
extern char const *
|
||||
__real_wfd_settings_get_string_or_default(
|
||||
struct wfd_settings * settings,
|
||||
char const * key,
|
||||
char const * default_value);
|
||||
|
||||
extern bool
|
||||
__real_wfd_settings_get_bool(
|
||||
struct wfd_settings * settings,
|
||||
char const * key);
|
||||
|
||||
char const *
|
||||
__wrap_wfd_settings_get_string(
|
||||
struct wfd_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get_string(settings, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->getString(key);
|
||||
}
|
||||
}
|
||||
|
||||
char const *
|
||||
__wrap_wfd_settings_get_string_or_default(
|
||||
struct wfd_settings * settings,
|
||||
char const * key,
|
||||
char const * default_value)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get_string_or_default(
|
||||
settings, key, default_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->getStringOrDefault(key, default_value);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
__wrap_wfd_settings_get_bool(
|
||||
struct wfd_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_settings)
|
||||
{
|
||||
return __real_wfd_settings_get_bool(settings, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_settings->getBool(key);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
MockSettings::MockSettings()
|
||||
{
|
||||
wfd_mock_settings = this;
|
||||
}
|
||||
|
||||
MockSettings::~MockSettings()
|
||||
{
|
||||
wfd_mock_settings = nullptr;
|
||||
}
|
||||
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
#define WFD_MOCK_AUTH_SETTINGS_HPP
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfused/config/settings.h"
|
||||
|
||||
namespace webfused_test
|
||||
{
|
||||
|
||||
class ISettings
|
||||
{
|
||||
public:
|
||||
virtual ~ISettings() = default;
|
||||
virtual char const * getString(char const * key) = 0;
|
||||
virtual char const * getStringOrDefault(char const * key, char const * default_value) = 0;
|
||||
virtual bool getBool(char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockSettings: public ISettings
|
||||
{
|
||||
public:
|
||||
MockSettings();
|
||||
~MockSettings() override;
|
||||
MOCK_METHOD1(getString, char const * (char const * key));
|
||||
MOCK_METHOD2(getStringOrDefault, char const * (char const * key, char const * default_value));
|
||||
MOCK_METHOD1(getBool, bool (char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,658 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfused/config/factory.h"
|
||||
#include "webfused/log/logger.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock_logger.hpp"
|
||||
#include "mock_config_builder.hpp"
|
||||
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::testing::StrictMock;
|
||||
using ::testing::StrEq;
|
||||
using ::webfused_test::MockLogger;
|
||||
using ::webfused_test::MockConfigBuilder;
|
||||
|
||||
TEST(config, is_loadable)
|
||||
{
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setLogger(_,_,_)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_CALL(builder, setServerVhostname(StrEq("localhost"))).Times(1);
|
||||
EXPECT_CALL(builder, setServerPort(8080)).Times(1);
|
||||
EXPECT_CALL(builder, addAuthProvider(_, _)).Times(1).WillOnce(Return(true));
|
||||
EXPECT_CALL(builder, addFilesystem(_,_)).Times(1).WillOnce(Return(true));
|
||||
|
||||
struct wfd_config * config = wfd_config_load_file("webfused.conf");
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, minimal_config)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
|
||||
char const minimal[] = "version = { major = 1, minor = 0 }\n";
|
||||
struct wfd_config * config = wfd_config_load_string(minimal);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, invalid_config)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(0);
|
||||
EXPECT_CALL(builder, dispose(_)).Times(0);
|
||||
|
||||
char const syntax_error[] = "version.major = 1\n";
|
||||
|
||||
wfd_config * config = wfd_config_load_string(syntax_error);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, invalid_config_file)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(0);
|
||||
EXPECT_CALL(builder, dispose(_)).Times(0);
|
||||
|
||||
struct wfd_config * config = wfd_config_load_file("invalid.conf");
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, invalid_major_version_too_low)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
|
||||
char const too_low[] = "version = { major = 0, minor = 0 }\n";
|
||||
|
||||
struct wfd_config * config= wfd_config_load_string(too_low);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, invalid_major_version_too_high)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
|
||||
char const too_high[] = "version = { major = 2, minor = 0 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, invalid_missing_major_version)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
|
||||
char const too_high[] = "version = { minor = 0 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, invalid_missing_minor_version)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
|
||||
char const too_high[] = "version = { major = 1 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, valid_older_minor)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
|
||||
char const valid[] = "version = { major = 1, minor = -1 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(valid);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, valid_newer_minor)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
|
||||
char const valid[] = "version = { major = 1, minor = 1 }\n";
|
||||
|
||||
struct wfd_config * config = wfd_config_load_string(valid);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, vhost_name)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setServerVhostname(StrEq("some.host"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" vhost_name = \"some.host\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, port)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setServerPort(54321)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" port = 54321\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, tls_certificate)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setServerCert(StrEq("/path/to/cert.pem"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" tls:\n"
|
||||
" {\n"
|
||||
" certificate = \"/path/to/cert.pem\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, tls_key)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setServerKey(StrEq("/path/to/key.pem"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" tls:\n"
|
||||
" {\n"
|
||||
" key = \"/path/to/key.pem\"\n"
|
||||
" }\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, document_root)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setServerDocumentRoot(StrEq("/var/www"))).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"server:\n"
|
||||
"{\n"
|
||||
" document_root = \"/var/www\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, authentication)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, addAuthProvider(_, _)).Times(1).WillOnce(Return(true));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, failed_create_authenticator)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, addAuthProvider(_, _)).Times(1).WillOnce(Return(false));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, failed_missing_auth_provider)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" settings: { }\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, failed_missing_auth_settings)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"authentication:\n"
|
||||
"(\n"
|
||||
" {\n"
|
||||
" provider = \"test\"\n"
|
||||
" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, filesystems)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, addFilesystem(_, _)).Times(1).WillOnce(Return(true));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, filesystems_empty)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, addFilesystem(_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, filesystems_failed_add)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, addFilesystem(_, _)).Times(1).WillOnce(Return(false));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, filesystems_failed_missing_name)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, addFilesystem(_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {mount_point = \"/tmp/test\" }\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, filesystems_failed_missing_mountpoint)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, addFilesystem(_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"filesystems:\n"
|
||||
"(\n"
|
||||
" {name = \"foo\"}\n"
|
||||
")\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, log)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setLogger(_, _, _)).Times(1).WillOnce(Return(true));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
" level = \"all\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, log_fail_set_logger)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, setLogger(_, _, _)).Times(1).WillOnce(Return(false));
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
" level = \"all\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, log_fail_missing_provider)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, setLogger(_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" level = \"all\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, log_fail_missing_level)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, setLogger(_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
" level = \"fancy\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, log_fail_invalid_level)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, setLogger(_, _, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"log:\n"
|
||||
"{\n"
|
||||
" provider = \"stderr\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, set_user)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, setUser(_, _)).Times(1);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"user:\n"
|
||||
"{\n"
|
||||
" name = \"webfused\"\n"
|
||||
" group = \"webfused\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_NE(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, set_user_fail_missing_name)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, setUser(_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"user:\n"
|
||||
"{\n"
|
||||
" group = \"webfused\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
||||
|
||||
TEST(config, set_user_fail_missing_group)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
StrictMock<MockConfigBuilder> builder;
|
||||
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||
EXPECT_CALL(builder, dispose(_)).Times(1);
|
||||
EXPECT_CALL(builder, setUser(_, _)).Times(0);
|
||||
|
||||
char const config_text[] =
|
||||
"version = { major = 1, minor = 0 }\n"
|
||||
"user:\n"
|
||||
"{\n"
|
||||
" name = \"webfused\"\n"
|
||||
"}\n"
|
||||
;
|
||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||
ASSERT_EQ(nullptr, config);
|
||||
}
|
407
test/userdb.cc
Normal file
407
test/userdb.cc
Normal file
@ -0,0 +1,407 @@
|
||||
#include "userdb/userdb.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(userdb, load_file)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
|
||||
bool success = userdb_load_file(db, "test_passwd.json");
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
ASSERT_TRUE(userdb_check(db, "bob", "secret"));
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_file_failed_no_file)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
|
||||
bool success = userdb_load_file(db, "non_existing.json");
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, save)
|
||||
{
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
userdb_add(db, "bob", "secret");
|
||||
ASSERT_TRUE(userdb_save(db, "/tmp/webfused_test.json"));
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
ASSERT_TRUE(userdb_load_file(db, "/tmp/webfused_test.json"));
|
||||
ASSERT_TRUE(userdb_check(db, "bob", "secret"));
|
||||
userdb_dispose(db);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(userdb, add)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
|
||||
userdb_add(db, "bob", "secret");
|
||||
ASSERT_TRUE(userdb_check(db, "bob", "secret"));
|
||||
ASSERT_FALSE(userdb_check(db, "bob", "i_dont_know"));
|
||||
ASSERT_FALSE(userdb_check(db, "anna", "secret"));
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, remove)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
ASSERT_NE(nullptr, db);
|
||||
|
||||
userdb_add(db, "bob", "secret");
|
||||
ASSERT_TRUE(userdb_check(db, "bob", "secret"));
|
||||
|
||||
userdb_remove(db, "bob");
|
||||
ASSERT_FALSE(userdb_check(db, "bob", "secret"));
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, update)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
ASSERT_NE(nullptr, db);
|
||||
|
||||
userdb_add(db, "bob", "secret");
|
||||
ASSERT_TRUE(userdb_check(db, "bob", "secret"));
|
||||
|
||||
userdb_add(db, "bob", "new_secret");
|
||||
ASSERT_FALSE(userdb_check(db, "bob", "secret"));
|
||||
ASSERT_TRUE(userdb_check(db, "bob", "new_secret"));
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_string)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_no_json)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] = "brummni";
|
||||
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_invalid_type)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"any-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_invalid_version)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 2,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_missing_type)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_type_not_string)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": 42,"
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_missing_major_version)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_major_version_not_int)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": false,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_missing_minor_version)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_minor_version_not_int)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": false,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_missing_hash_alg)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_hash_alg_not_string)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": 42"
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_missing_meta)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, load_fail_unsupported_hash)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"brummni\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_FALSE(success);
|
||||
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, fail_missing_user_salt)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
" \"bob\": {"
|
||||
" \"password_hash\": \"e51e27ce47054feead3d83068d47f2a07307d4877ac67da668ef43e0e466fe8c7b66651af14fdb8d48c51592ef5afa0c63f874d20861c6b9ef8e6513bfcaa330\""
|
||||
" }"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
ASSERT_FALSE(userdb_check(db, "bob", "secret"));
|
||||
userdb_dispose(db);
|
||||
}
|
||||
|
||||
TEST(userdb, fail_missing_user_hash)
|
||||
{
|
||||
userdb * db = userdb_create("");
|
||||
char const contents[] =
|
||||
"{"
|
||||
"\"meta\": {"
|
||||
" \"type\": \"wf-userdb\","
|
||||
" \"major\": 1,"
|
||||
" \"minor\": 0,"
|
||||
" \"hash_algorithm\": \"sha512\""
|
||||
"},"
|
||||
"\"users\": {"
|
||||
" \"bob\": {"
|
||||
" \"salt\": \"b3be6979921edecfea88c50d0d1ec40b7f8c383831b2276c65969ead18e47c03\""
|
||||
" }"
|
||||
"}"
|
||||
"}"
|
||||
;
|
||||
bool success = userdb_load_string(db, contents);
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
ASSERT_FALSE(userdb_check(db, "bob", "secret"));
|
||||
userdb_dispose(db);
|
||||
}
|
74
test/util/wrap.hpp
Normal file
74
test/util/wrap.hpp
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef WFD_UTIL_WRAP_HPP
|
||||
#define WFD_UTIL_WRAP_HPP
|
||||
|
||||
#define WFD_WRAP_FUNC0( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME ) \
|
||||
extern RETURN_TYPE __real_ ## FUNC_NAME (); \
|
||||
RETURN_TYPE __wrap_ ## FUNC_NAME () \
|
||||
{ \
|
||||
if (nullptr == GLOBAL_VAR ) \
|
||||
{ \
|
||||
return __real_ ## FUNC_NAME (); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
return GLOBAL_VAR -> FUNC_NAME(); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WFD_WRAP_FUNC1( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE ) \
|
||||
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE); \
|
||||
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1) \
|
||||
{ \
|
||||
if (nullptr == GLOBAL_VAR ) \
|
||||
{ \
|
||||
return __real_ ## FUNC_NAME (arg1); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
return GLOBAL_VAR -> FUNC_NAME(arg1); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WFD_WRAP_FUNC2( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE ) \
|
||||
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE); \
|
||||
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2) \
|
||||
{ \
|
||||
if (nullptr == GLOBAL_VAR ) \
|
||||
{ \
|
||||
return __real_ ## FUNC_NAME (arg1, arg2); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
return GLOBAL_VAR -> FUNC_NAME(arg1, arg2); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WFD_WRAP_FUNC3( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE ) \
|
||||
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE); \
|
||||
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3) \
|
||||
{ \
|
||||
if (nullptr == GLOBAL_VAR ) \
|
||||
{ \
|
||||
return __real_ ## FUNC_NAME (arg1, arg2, arg3); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define WFD_WRAP_FUNC4( GLOBAL_VAR, RETURN_TYPE, FUNC_NAME, ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE ) \
|
||||
extern RETURN_TYPE __real_ ## FUNC_NAME (ARG1_TYPE, ARG2_TYPE, ARG3_TYPE, ARG4_TYPE); \
|
||||
RETURN_TYPE __wrap_ ## FUNC_NAME (ARG1_TYPE arg1, ARG2_TYPE arg2, ARG3_TYPE arg3, ARG4_TYPE arg4) \
|
||||
{ \
|
||||
if (nullptr == GLOBAL_VAR ) \
|
||||
{ \
|
||||
return __real_ ## FUNC_NAME (arg1, arg2, arg3, arg4); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
return GLOBAL_VAR -> FUNC_NAME(arg1, arg2, arg3, arg4); \
|
||||
} \
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user