Test the authentication plug-ins for compliance
This commit is contained in:
parent
5a98234072
commit
a28727be7d
|
@ -2,5 +2,5 @@ package=Locker
|
|||
version=0.3.0
|
||||
config=h,sh
|
||||
|
||||
subdirs=data,doc,include,po,src,tools
|
||||
subdirs=data,doc,include,po,src,tests,tools
|
||||
dist=COPYING,Makefile,config.h,config.sh
|
||||
|
|
134
tests/auth.c
Normal file
134
tests/auth.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2015 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Desktop Locker */
|
||||
/* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
|
||||
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
#include "Locker.h"
|
||||
|
||||
/* constants */
|
||||
#define PROGNAME "auth"
|
||||
|
||||
|
||||
/* private */
|
||||
/* prototypes */
|
||||
static int _auth(void);
|
||||
|
||||
static int _dlerror(char const * message, int ret);
|
||||
static int _error(char const * message, char const * error, int ret);
|
||||
static int _perror(char const * message, int ret);
|
||||
|
||||
|
||||
/* functions */
|
||||
/* applets */
|
||||
static int _auth(void)
|
||||
{
|
||||
int ret = 0;
|
||||
const char path[] = "../src/auth";
|
||||
#ifdef __APPLE__
|
||||
const char ext[] = ".dylib";
|
||||
#else
|
||||
const char ext[] = ".so";
|
||||
#endif
|
||||
DIR * dir;
|
||||
struct dirent * de;
|
||||
size_t len;
|
||||
char * s;
|
||||
void * p;
|
||||
LockerAuthDefinition * lad;
|
||||
|
||||
if((dir = opendir(path)) == NULL)
|
||||
return -_perror(path, 1);
|
||||
while((de = readdir(dir)) != NULL)
|
||||
{
|
||||
if((len = strlen(de->d_name)) < sizeof(ext))
|
||||
continue;
|
||||
if(strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0)
|
||||
continue;
|
||||
if((s = malloc(sizeof(path) + len + 1)) == NULL)
|
||||
{
|
||||
ret += _perror(de->d_name, 1);
|
||||
continue;
|
||||
}
|
||||
snprintf(s, sizeof(path) + len + 1, "%s/%s", path, de->d_name);
|
||||
if((p = dlopen(s, RTLD_LAZY)) == NULL)
|
||||
{
|
||||
ret += _dlerror(s, 1);
|
||||
free(s);
|
||||
continue;
|
||||
}
|
||||
if((lad = dlsym(p, "plugin")) == NULL)
|
||||
ret += _dlerror(s, 1);
|
||||
else
|
||||
{
|
||||
if(lad->icon == NULL)
|
||||
ret += _error(s, "No icon defined", 1);
|
||||
else
|
||||
printf("\n%s: %s (%s)\n%s\n", de->d_name,
|
||||
lad->name, lad->icon,
|
||||
(lad->description != NULL)
|
||||
? lad->description
|
||||
: "(no description)");
|
||||
if(lad->get_widget == NULL)
|
||||
ret += _error(s, "No widget available", 1);
|
||||
if(lad->action == NULL)
|
||||
ret += _error(s, "No action handler", 1);
|
||||
}
|
||||
free(s);
|
||||
dlclose(p);
|
||||
}
|
||||
closedir(dir);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* dlerror */
|
||||
static int _dlerror(char const * message, int ret)
|
||||
{
|
||||
fputs(PROGNAME ": ", stderr);
|
||||
fprintf(stderr, "%s: %s\n", message, dlerror());
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* error */
|
||||
static int _error(char const * message, char const * error, int ret)
|
||||
{
|
||||
fputs(PROGNAME ": ", stderr);
|
||||
fprintf(stderr, "%s: %s\n", message, error);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* perror */
|
||||
static int _perror(char const * message, int ret)
|
||||
{
|
||||
fputs(PROGNAME ": ", stderr);
|
||||
perror(message);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* public */
|
||||
/* functions */
|
||||
/* main */
|
||||
int main(void)
|
||||
{
|
||||
return (_auth() == 0) ? 0 : 2;
|
||||
}
|
15
tests/project.conf
Normal file
15
tests/project.conf
Normal file
|
@ -0,0 +1,15 @@
|
|||
targets=auth,tests.log
|
||||
cppflags_force=-I ../include
|
||||
cflags_force=-W `pkg-config --cflags libDesktop`
|
||||
cflags=-Wall -g -O2
|
||||
ldflags_force=-W `pkg-config --libs libDesktop`
|
||||
dist=Makefile,tests.sh
|
||||
|
||||
[auth]
|
||||
type=binary
|
||||
sources=auth.c
|
||||
|
||||
[tests.log]
|
||||
type=script
|
||||
script=./tests.sh
|
||||
depends=$(OBJDIR)auth,tests.sh
|
109
tests/tests.sh
Executable file
109
tests/tests.sh
Executable file
|
@ -0,0 +1,109 @@
|
|||
#!/bin/sh
|
||||
#$Id$
|
||||
#Copyright (c) 2015 Pierre Pronchery <khorben@defora.org>
|
||||
#This file is part of DeforaOS Desktop Locker
|
||||
#This program is free software: you can redistribute it and/or modify
|
||||
#it under the terms of the GNU General Public License as published by
|
||||
#the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
#This program is distributed in the hope that it will be useful,
|
||||
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
#GNU General Public License for more details.
|
||||
#
|
||||
#You should have received a copy of the GNU General Public License
|
||||
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#variables
|
||||
[ -n "$OBJDIR" ] || OBJDIR="./"
|
||||
PROGNAME="tests.sh"
|
||||
#executables
|
||||
DATE="date"
|
||||
|
||||
|
||||
#functions
|
||||
#fail
|
||||
_fail()
|
||||
{
|
||||
test="$1"
|
||||
|
||||
shift
|
||||
echo -n "$test:" 1>&2
|
||||
(echo
|
||||
echo "Testing: $OBJDIR$test" "$@"
|
||||
"$OBJDIR$test" "$@") >> "$target" 2>&1
|
||||
res=$?
|
||||
if [ $res -ne 0 ]; then
|
||||
echo " FAILED (error $res)" 1>&2
|
||||
else
|
||||
echo " PASS" 1>&2
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#test
|
||||
_test()
|
||||
{
|
||||
test="$1"
|
||||
|
||||
shift
|
||||
echo -n "$test:" 1>&2
|
||||
(echo
|
||||
echo "Testing: $OBJDIR$test" "$@"
|
||||
"$OBJDIR$test" "$@") >> "$target" 2>&1
|
||||
res=$?
|
||||
if [ $res -ne 0 ]; then
|
||||
echo " FAILED" 1>&2
|
||||
FAILED="$FAILED $test(error $res)"
|
||||
return 2
|
||||
else
|
||||
echo " PASS" 1>&2
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
#usage
|
||||
_usage()
|
||||
{
|
||||
echo "Usage: $PROGNAME [-c][-P prefix]" 1>&2
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
#main
|
||||
clean=0
|
||||
while getopts "cP:" name; do
|
||||
case "$name" in
|
||||
c)
|
||||
clean=1
|
||||
;;
|
||||
P)
|
||||
#XXX ignored
|
||||
;;
|
||||
?)
|
||||
_usage
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
if [ $# -ne 1 ]; then
|
||||
_usage
|
||||
exit $?
|
||||
fi
|
||||
target="$1"
|
||||
|
||||
[ "$clean" -ne 0 ] && exit 0
|
||||
|
||||
$DATE > "$target"
|
||||
FAILED=
|
||||
echo "Performing tests:" 1>&2
|
||||
echo "Expected failures:" 1>&2
|
||||
_fail "auth"
|
||||
if [ -n "$FAILED" ]; then
|
||||
echo "Failed tests:$FAILED" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
echo "All tests completed" 1>&2
|
Loading…
Reference in New Issue
Block a user