Browse Source

Fixing -a with not valid attacks: check before the file is given.

Unnittesting this, adding test_cmdline.test.
Michele Orrù 11 years ago
parent
commit
e223759bb5
3 changed files with 13 additions and 10 deletions
  1. 4 8
      src/qa.c
  2. 1 2
      src/tests/Makefile.am
  3. 8 0
      src/tests/test_cmdline.test

+ 4 - 8
src/qa.c

@@ -127,6 +127,10 @@ qa_init(const struct qa_conf* conf)
   /* Initialize SSL Library by registering algorithms. */
   SSL_library_init();
 
+  if (!conf->attacks) select_all_questions();
+  else select_question(conf->attacks);
+  if (!questions.lh_first) error(EXIT_FAILURE, 0, "No valid question selected.");
+
   if (conf->src_type == REMOTE)
     crt = get_remote_cert(conf->src);
   else if (conf->src_type == LOCAL_X509)
@@ -135,18 +139,10 @@ qa_init(const struct qa_conf* conf)
     rsa = get_local_rsa(conf->src);
   else
     error(EXIT_FAILURE, 0, "iternal error: unable to determine source type.");
-
   if (!crt && !rsa)
     error(EXIT_FAILURE, errno, "Unable to open source.");
 
-
-  if (!conf->attacks) select_all_questions();
-  else select_question(conf->attacks);
-
-  if (!questions.lh_first) error(EXIT_FAILURE, 0, "No valid question selected.");
-
   exitcode = qa_dispose(crt, rsa);
-
   X509_free(crt);
   return exitcode;
 }

+ 1 - 2
src/tests/Makefile.am

@@ -3,11 +3,10 @@ AM_CFLAGS = -I ../include/
 AM_LDFLAGS = -lcrypto -lssl
 
 check_PROGRAMS = test_qa_sock test_qa
+TESTS = $(check_PROGRAMS) test_cmdline.test
 
 test_qa_sock_SOURCES = test_qa_sock.c
 test_qa_sock_LDADD = ../qa_sock.o
 
 test_qa_SOURCES = test_qa.c
 test_qa_LDADD = ../qa_sock.o ../qa.o ../questions/allquestions.o ../questions/libquestions.a
-
-TESTS = $(check_PROGRAMS)

+ 8 - 0
src/tests/test_cmdline.test

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+../qa -a non_existing_test < /dev/null
+if [ $? -ne 1 ]
+then
+    echo "Invalid questions shall raise an error."
+    exit 1
+fi