aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-20 18:51:15 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-20 18:54:17 +0300
commitdf59e148ac7b5fa46959c89f206572738735e121 (patch)
treefac2ec0d01632ee60135d4427364e808b829e459
parent4caaf454b507722908a642d25034837108ccaf16 (diff)
downloadwydawca-df59e148ac7b5fa46959c89f206572738735e121.tar.gz
wydawca-df59e148ac7b5fa46959c89f206572738735e121.tar.bz2
Add tests for legacy upload notification interface
* src/net.c (handle_connection): Ignore user/comment. * tests/.gitignore: Add wyclt. * tests/wyclt.c: New file. * tests/Makefile.am (TESTSUITE_AT): Add new tests. * tests/unp-idle.at: New test. * tests/unp00.at: New test. * tests/unp01.at: New test. * tests/testsuite.at (AT_WYDAWCA_DAEMON): Change arguments. (AT_WYDAWCA_INOTIFY_DAEMON): New macro. Include new tests.
-rw-r--r--src/net.c16
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am9
-rw-r--r--tests/inotify-ok.at3
-rw-r--r--tests/inotify-rmsymlink.at4
-rw-r--r--tests/inotify-symlink.at4
-rw-r--r--tests/inotify-unatt00.at3
-rw-r--r--tests/inotify-unatt01.at3
-rw-r--r--tests/testsuite.at24
-rw-r--r--tests/unp-idle.at22
-rw-r--r--tests/unp00.at48
-rw-r--r--tests/unp01.at51
-rw-r--r--tests/wyclt.c78
13 files changed, 235 insertions, 31 deletions
diff --git a/src/net.c b/src/net.c
index f0869dc..62d2fef 100644
--- a/src/net.c
+++ b/src/net.c
@@ -207,7 +207,6 @@ handle_connection(struct wydawca_connection *conn)
char *buf = NULL;
size_t buflen = 0;
struct spool *spool;
- char *p;
if (grecs_getline(&buf, &buflen, conn->fp) <= 0)
return;
@@ -238,16 +237,6 @@ handle_connection(struct wydawca_connection *conn)
wy_debug(1, ("recv: %s", buf));
/* FIXME: User name not used any more */
- p = strchr(buf, ' ');
- if (p) {
- *p++ = 0;
- while (*p && (*p == ' ' || *p == '\t'))
- p++;
- } else {
- wy_log(LOG_ERR, "protocol error");
- free(buf);
- return;
- }
if (spool)
scan_spool(spool);
@@ -281,9 +270,10 @@ wy_thr_connection_watcher(void *ptr)
clock_gettime(CLOCK_REALTIME, &ts);
if (timespec_cmp(&ts, &conn_idle.head->ts) >= 0) {
void *ret;
- pthread_cancel(conn_idle.head->tid);
+ pthread_t tid = conn_idle.head->tid;
+ pthread_cancel(tid);
pthread_mutex_unlock(&conn_mutex);
- pthread_join(conn_idle.head->tid, &ret);
+ pthread_join(tid, &ret);
pthread_mutex_lock(&conn_mutex);
}
}
diff --git a/tests/.gitignore b/tests/.gitignore
index 6026f18..e5a908e 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -8,4 +8,5 @@ bkupname
nullmail
cwdrepl
wyasync
+wyclt
wyinit
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 285870f..fb971d5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,6 +63,9 @@ TESTSUITE_AT = \
upl11.at\
upl12f.at\
upl12t.at\
+ unp00.at\
+ unp01.at\
+ unp-idle.at\
version.at
TESTSUITE = $(srcdir)/testsuite
@@ -86,7 +89,7 @@ check-local: atconfig atlocal $(TESTSUITE)
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
-check_PROGRAMS = bkupname cwdrepl wyinit
+check_PROGRAMS = bkupname cwdrepl wyinit wyasync wyclt
AM_CPPFLAGS = \
@GRECS_INCLUDES@ \
-I$(top_srcdir)/include\
@@ -96,10 +99,6 @@ LDADD=@GRECS_LDADD@
bkupname_LDADD=../src/backup.o @GRECS_LDADD@
wyinit_LDADD=@GRECS_LDADD@
-if COND_INOTIFY
- check_PROGRAMS += wyasync
-endif
-
if COND_MAILUTILS
check_PROGRAMS += nullmail
nullmail_LDADD = @MAILUTILS_LIBS@
diff --git a/tests/inotify-ok.at b/tests/inotify-ok.at
index bfe7301..3b12ab2 100644
--- a/tests/inotify-ok.at
+++ b/tests/inotify-ok.at
@@ -39,7 +39,7 @@ wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
-AT_WYDAWCA_DAEMON([],
+AT_WYDAWCA_INOTIFY_DAEMON([],
[wydawca_upload ok file
while ! test -f @CWD@/dest/proj/file && ! test -f @CWD@/dest/proj/file.sig
do
@@ -48,6 +48,7 @@ done
],
[wydawca_cmp proj file file.sig
],
+[0],
[],
[experr])
diff --git a/tests/inotify-rmsymlink.at b/tests/inotify-rmsymlink.at
index 67819ba..4c36a37 100644
--- a/tests/inotify-rmsymlink.at
+++ b/tests/inotify-rmsymlink.at
@@ -40,8 +40,9 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_WYDAWCA_DAEMON([
+AT_INOTIFY_PREREQ
AT_SORT_PREREQ
-mkdir dest/proj
+],[mkdir dest/proj
cp "$WY_DISTDIR/file" "$WY_DISTDIR/file.sig" dest/proj
(cd dest/proj && ln -sf file file-latest && ln -sf file.sig file-latest.sig)
],
@@ -54,6 +55,7 @@ done
],
[find dest -type l | sort
],
+[0],
[],
[experr])
diff --git a/tests/inotify-symlink.at b/tests/inotify-symlink.at
index dd690ee..5999cb6 100644
--- a/tests/inotify-symlink.at
+++ b/tests/inotify-symlink.at
@@ -41,7 +41,8 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
AT_WYDAWCA_DAEMON([
AT_SORT_PREREQ
-mkdir dest/proj
+AT_INOTIFY_PREREQ],
+[mkdir dest/proj
cp "$WY_DISTDIR/file" "$WY_DISTDIR/file.sig" dest/proj
],
[cp "$WY_DISTDIR/symlink.directive.asc" source/test
@@ -54,6 +55,7 @@ done
[find dest -type l | sort
find dest -type l | sort | xargs -n 1 readlink
],
+[0],
[dest/proj/file-latest
dest/proj/file-latest.sig
file
diff --git a/tests/inotify-unatt00.at b/tests/inotify-unatt00.at
index aaba627..e87a80d 100644
--- a/tests/inotify-unatt00.at
+++ b/tests/inotify-unatt00.at
@@ -39,7 +39,7 @@ wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
-AT_WYDAWCA_DAEMON([
+AT_WYDAWCA_INOTIFY_DAEMON([
wydawca_upload ok file
],
[while ! test -f @CWD@/dest/proj/file && ! test -f @CWD@/dest/proj/file.sig
@@ -49,6 +49,7 @@ done
],
[wydawca_cmp proj file file.sig
],
+[0],
[],
[experr])
AT_CLEANUP
diff --git a/tests/inotify-unatt01.at b/tests/inotify-unatt01.at
index b198a6e..9451a92 100644
--- a/tests/inotify-unatt01.at
+++ b/tests/inotify-unatt01.at
@@ -39,7 +39,7 @@ wydawca: [[NOTICE]] shutting down on signal "Terminated"
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
-AT_WYDAWCA_DAEMON([
+AT_WYDAWCA_INOTIFY_DAEMON([
cp "$WY_DISTDIR/file" "source/ok/$dir"
cp "$WY_DISTDIR/file.sig" "source/ok/$dir"
],
@@ -51,6 +51,7 @@ done
],
[wydawca_cmp proj file file.sig
],
+[0],
[],
[experr])
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 06b0b0c..511175f 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -26,10 +26,10 @@ test -z "`sort < /dev/null 2>&1`" || AT_SKIP_TEST
m4_define([AT_MAILUTILS_PREREQ],[test "$WY_MAILUTILS" = yes || AT_SKIP_TEST])
m4_define([AT_INOTIFY_PREREQ],[test "$WY_INOTIFY" = yes || AT_SKIP_TEST])
-# AT_WYDAWCA_DAEMON([INI],[SHELL-COMMANDS],[POST],[STDOUT],[STDERR])
+# AT_WYDAWCA_DAEMON([PREREQ],[INI],[SHELL-COMMANDS],[POST],[CODE],[STDOUT],[STDERR])
m4_define([AT_WYDAWCA_DAEMON],
-[AT_CHECK([AT_INOTIFY_PREREQ
-AT_DATA([helper.in],[$2
+[AT_CHECK([$1
+AT_DATA([helper.in],[$3
])
cat > helper.sh <<EOT
#!/bin/sh
@@ -38,15 +38,18 @@ EOT
wydawca_expandmeta helper.in helper.bot
cat helper.bot >> helper.sh
wydawca_config wydawca.cf
-$1
+$2
wyasync -c $PWD/wydawca.cf -w --no-preproc -- /bin/sh ./helper.sh || exit $?
-$3
+$4
cat wydawca.out | cwdrepl
cat wydawca.err | cwdrepl >&2
],
-[0],
-[$4],
-[$5])])
+[$5],
+[$6],
+[$7])])
+
+m4_define([AT_WYDAWCA_INOTIFY_DAEMON],
+[AT_WYDAWCA_DAEMON([AT_INOTIFY_PREREQ],$@)])
AT_INIT
AT_TESTED([wydawca])
@@ -83,3 +86,8 @@ m4_include([inotify-symlink.at])
m4_include([inotify-rmsymlink.at])
m4_include([inotify-unatt00.at])
m4_include([inotify-unatt01.at])
+
+AT_BANNER([Legacy upload notification protocol])
+m4_include([unp00.at])
+m4_include([unp01.at])
+m4_include([unp-idle.at])
diff --git a/tests/unp-idle.at b/tests/unp-idle.at
new file mode 100644
index 0000000..ba78cef
--- /dev/null
+++ b/tests/unp-idle.at
@@ -0,0 +1,22 @@
+AT_SETUP([Idle timeout])
+AT_KEYWORDS([uploads unp unp-idle])
+
+AT_WYDAWCA_DAEMON([
+AT_SORT_PREREQ
+socket=$(pwd)/wydawca.s
+export socket uploaddir GNUPGHOME
+],
+[cat >> wydawca.cf <<EOT
+inotify no;
+listen $socket;
+EOT
+],
+[wyclt -w 7 $socket ckok
+],
+[],
+[2],
+[],
+[SIGPIPE
+])
+
+AT_CLEANUP
diff --git a/tests/unp00.at b/tests/unp00.at
new file mode 100644
index 0000000..fb2cd6e
--- /dev/null
+++ b/tests/unp00.at
@@ -0,0 +1,48 @@
+AT_SETUP([Successful upload])
+AT_KEYWORDS([uploads unp unp00])
+
+AT_DATA([experr],
+[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
+wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
+wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
+wydawca: [[INFO]] errors: 0
+wydawca: [[INFO]] warnings: 0
+wydawca: [[INFO]] bad signatures: 0
+wydawca: [[INFO]] access violation attempts: 0
+wydawca: [[INFO]] complete triplets: 1
+wydawca: [[INFO]] incomplete triplets: 0
+wydawca: [[INFO]] bad triplets: 0
+wydawca: [[INFO]] expired triplets: 0
+wydawca: [[INFO]] triplet successes: 1
+wydawca: [[INFO]] files uploaded: 2
+wydawca: [[INFO]] files archived: 0
+wydawca: [[INFO]] symlinks created: 0
+wydawca: [[INFO]] symlinks removed: 0
+wydawca: [[INFO]] check failures: 0
+wydawca: [[NOTICE]] shutting down on signal "Terminated"
+wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
+])
+
+AT_WYDAWCA_DAEMON([
+socket=$(pwd)/wydawca.s
+export socket
+],
+[cat >> wydawca.cf <<EOT
+inotify no;
+listen $socket;
+EOT
+],
+[wydawca_upload ok file
+wyclt $socket ckok
+while ! test -f @CWD@/dest/proj/file && ! test -f @CWD@/dest/proj/file.sig
+do
+ sleep 1
+done
+],
+[wydawca_cmp proj file file.sig
+],
+[0],
+[],
+[experr])
+
+AT_CLEANUP
diff --git a/tests/unp01.at b/tests/unp01.at
new file mode 100644
index 0000000..d59ba5c
--- /dev/null
+++ b/tests/unp01.at
@@ -0,0 +1,51 @@
+AT_SETUP([Multiple successful uploads])
+AT_KEYWORDS([uploads unp unp01])
+
+AT_WYDAWCA_DAEMON([
+AT_SORT_PREREQ
+socket=$(pwd)/wydawca.s
+uploaddir=$(pwd)/source/ok
+GNUPGHOME=$WY_CONFSRC
+export socket uploaddir GNUPGHOME
+],
+[cat >> wydawca.cf <<EOT
+inotify no;
+listen $socket;
+EOT
+],
+[
+upload() {
+ name=$1
+ shift
+ echo "$@" > $uploaddir/$name
+ gpg --batch --no-tty -ba \
+ -o $uploaddir/$name.sig $uploaddir/$name
+ cat > $name.directive <<EOT
+version: 1.2
+directory: proj
+filename: $name
+EOT
+ gpg --batch --no-tty --clearsign \
+ -o $uploaddir/$name.directive.asc $name.directive
+}
+
+upload one "first distro" 2>gpg.err
+upload two "second distro" 2>>gpg.err
+
+wyclt $socket ckok
+while ! test -f @CWD@/dest/proj/one && ! test -f @CWD@/dest/proj/one.sig
+do
+ sleep 1
+done
+],
+[find dest -type f|sort
+],
+[0],
+[dest/proj/one
+dest/proj/one.sig
+dest/proj/two
+dest/proj/two.sig
+],
+[ignore])
+
+AT_CLEANUP
diff --git a/tests/wyclt.c b/tests/wyclt.c
new file mode 100644
index 0000000..f9f2d38
--- /dev/null
+++ b/tests/wyclt.c
@@ -0,0 +1,78 @@
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <assert.h>
+#include <unistd.h>
+#include <signal.h>
+
+void
+sigpipe(int sig)
+{
+ fprintf(stderr, "SIGPIPE\n");
+ exit(2);
+}
+
+int
+main(int argc, char **argv)
+{
+ struct sockaddr_un s_un;
+ int fd;
+ FILE *fp;
+ char buf[128];
+ char *p;
+ int ttw = 0;
+ int c;
+
+ while ((c = getopt(argc, argv, "w:")) != EOF) {
+ switch (c) {
+ case 'w':
+ ttw = atoi(optarg);
+ assert(ttw >= 0);
+ break;
+
+ default:
+ return 1;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ assert(argc == 2);
+ assert(strlen(argv[0]) < sizeof(s_un.sun_path));
+ strcpy(s_un.sun_path, argv[0]);
+ s_un.sun_family = AF_UNIX;
+ fd = socket(s_un.sun_family, SOCK_STREAM, 0);
+ if (fd == -1) {
+ perror("socket");
+ abort();
+ }
+
+ if (connect(fd, (const struct sockaddr *) &s_un, sizeof(s_un)) == -1) {
+ perror("connect");
+ abort();
+ }
+
+ signal(SIGPIPE, sigpipe);
+ if (ttw)
+ sleep(ttw);
+
+ fp = fdopen(fd, "w+");
+ if (!fp) {
+ perror("fdopen");
+ }
+
+ fprintf(fp, "%s\r\n", argv[1]);
+ p = fgets(buf, sizeof(buf), fp);
+ assert(p != NULL);
+ if (p[0] != '+') {
+ fprintf(stderr, "unexpected: %s\n", buf);
+ abort();
+ }
+ fprintf(fp, "%s\r\n", "user");
+ fclose(fp);
+ return 0;
+}
+
+
+

Return to:

Send suggestions and report system problems to the System administrator.