Leosac  0.7.0
OpenSourceAccessControl
AuthSourceBuilder.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
21 #include "core/auth/Auth.hpp"
27 #include <gtest/gtest.h>
28 
29 using namespace Leosac::Auth;
30 using namespace Leosac::Module::Auth;
31 
32 namespace Leosac
33 {
34 namespace Test
35 {
40 class AuthSourceBuilderTest : public ::testing::Test
41 {
42  public:
44  {
45  msg1_ << "S_MY_WIEGAND_1";
47  msg1_ << "af:bc:12:42";
48  msg1_ << 32;
49 
50  msg2_ << "S_MY_WIEGAND_1";
51  msg2_ << SourceType::WIEGAND_PIN;
52  msg2_ << "1234";
53 
54  msg3_ << "S_MY_WIEGAND_1";
56  msg3_ << "af:bc:12:42";
57  msg3_ << 32;
58  msg3_ << "1234";
59  }
60 
62  {
63  }
64 
69  zmqpp::message msg1_;
70 
74  zmqpp::message msg2_;
75 
79  zmqpp::message msg3_;
80 };
81 
82 TEST_F(AuthSourceBuilderTest, ExtractSourceName)
83 {
84  std::string out;
85 
86  ASSERT_TRUE(builder_.extract_source_name("S_MY_DEVICE", &out));
87  ASSERT_EQ(out, "MY_DEVICE");
88 
89  ASSERT_TRUE(builder_.extract_source_name("S___MY_DEVICE", &out));
90  ASSERT_EQ(out, "__MY_DEVICE");
91 
92  ASSERT_FALSE(builder_.extract_source_name("MY_DEVICE", &out));
93  ASSERT_FALSE(builder_.extract_source_name("", &out));
94  ASSERT_FALSE(builder_.extract_source_name("S_", &out));
95  ASSERT_FALSE(builder_.extract_source_name("D", &out));
96 }
97 
98 TEST_F(AuthSourceBuilderTest, BuildWiegandCard)
99 {
100  Cred::ICredentialPtr auth_source = builder_.create(&msg1_);
101  ASSERT_TRUE(auth_source.get());
102 
103  // ASSERT_EQ(auth_source->name(), "MY_WIEGAND_1");
104  Cred::RFIDCardPtr spec = std::dynamic_pointer_cast<Cred::RFIDCard>(auth_source);
105  ASSERT_TRUE(spec.get());
106  ASSERT_EQ("af:bc:12:42", spec->card_id());
107  ASSERT_EQ(32, spec->nb_bits());
108 }
109 
111 {
112  Cred::ICredentialPtr auth_source = builder_.create(&msg2_);
113  ASSERT_TRUE(auth_source.get());
114 
115  // ASSERT_EQ(auth_source->name(), "MY_WIEGAND_1");
116  Cred::PinCodePtr spec = std::dynamic_pointer_cast<Cred::PinCode>(auth_source);
117  ASSERT_TRUE(spec.get());
118  ASSERT_EQ("1234", spec->pin_code());
119 }
120 
121 TEST_F(AuthSourceBuilderTest, BuildCardAndPing)
122 {
123  Cred::ICredentialPtr auth_source = builder_.create(&msg3_);
124  ASSERT_TRUE(auth_source.get());
125 
126  // ASSERT_EQ(auth_source->name(), "MY_WIEGAND_1");
127  Cred::RFIDCardPinPtr spec =
128  std::dynamic_pointer_cast<Cred::RFIDCardPin>(auth_source);
129  ASSERT_TRUE(spec.get());
130  ASSERT_EQ("af:bc:12:42", spec->card().card_id());
131  ASSERT_EQ(32, spec->card().nb_bits());
132  ASSERT_EQ("1234", spec->pin().pin_code());
133 }
134 }
135 }
std::shared_ptr< PinCode > PinCodePtr
This define message formatting for data source SIMPLE_WIEGAND.
This is the header file for a generated source file, GitSHA1.cpp.
zmqpp::message msg1_
This looks like a message sent by MY_WIEGAND_1 with SIMPLE_WIEGAND data.
std::shared_ptr< RFIDCard > RFIDCardPtr
TEST_F(AuthSourceBuilderTest, BuildCardAndPing)
A PinCode credential.
Definition: PinCode.hpp:33
std::shared_ptr< ICredential > ICredentialPtr
Credentials composed of an RFIDCard and a PIN code.
Definition: RFIDCardPin.hpp:37
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
Message formatting when using a simple PIN code.
zmqpp::message msg3_
Message to construct a cardId + pin credential.
Authentication backend modules live here.
This class is some kind of factory to create IAuthenticationSource object from a zmqpp::message sent ...
std::shared_ptr< RFIDCardPin > RFIDCardPinPtr
When reading both a card an a PIN code.
zmqpp::message msg2_
This looks like a message sent by MY_WIEGAND_1 with WIEGAND_PIN_4BITS data.
Test the AuthSourceBuilder ability to create AuthSource object from messages.
An RFID card credential.
Definition: RFIDCard.hpp:33