summaryrefslogtreecommitdiffhomepage
path: root/tests/test-auth.cpp
blob: 37bc02ff053d8b5f491f27661d88ca4120fe1a2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <boost/test/unit_test.hpp>
#include <boost/test/data/dataset.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <boost/test/data/test_case.hpp>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

#include <sstream>
#include <string>

#include "auth.h"

using namespace std::string_literals;

class AuthFixture
{
public:
 AuthFixture(){}
 ~AuthFixture(){}
 void setup()
 {
  int filedes[2];
  if (pipe(filedes) == -1)
   throw std::runtime_error("Pipe error");
  if (close(2) == -1)
   throw std::runtime_error("Can't close stderr");
  if (dup(filedes[1]) == -1)
   throw std::runtime_error("Replace stdout w/ pipe input");
 }
 void teardown(){}
};

BOOST_FIXTURE_TEST_CASE(generate, AuthFixture)
{
 std::string pw0 {Auth::generate("")};
 BOOST_CHECK_GT(pw0.size(), 0);
 std::string pw1 {Auth::generate("abc")};
 BOOST_CHECK_GT(pw1.size(), 0);

 BOOST_CHECK_NE(pw0, pw1);
}

BOOST_FIXTURE_TEST_CASE(validate, AuthFixture)
{
 BOOST_CHECK(Auth::validate("t5MMkLQXzYkdw", "abc"));

 BOOST_CHECK(!Auth::validate("", ""));
 BOOST_CHECK(!Auth::validate("abc", "abc"));
 BOOST_CHECK(!Auth::validate("t5MNkLQXzYkdw", "abc"));
}