* Fix log file access, refactor configuration reading class * Remove bypass option in favor of failmode * fix loging, print enrolment info * Add EMAIL method * Add yubi authentication method * Add support for verification message * Add verification * Made changes in Vagrant's files to run different OSs * Switch off tests and packages demands to run PAM on Debian 11 * Add authentication totp * Changes in utils * Remove unnessesary interface * Changed vagrant files and postinstal script for Ubuntu 20 and 22 * Moved adding PasswordAuth to vagrant file from posinst * Added ubuntu 24.04 * Set version * Poprawki UI * WebSocket implementation * Add totp authentication method * fixup changes in utils * Remove unnessesary interface and simplify code * Remove "default" message handler from WebSocket class * Change display names of known authentication methods * Cleanup code in 'main' file * Add CheckApplication * Remove unused function * Changed vagrant files and postinstal script for Ubuntu 20 and 22 * Moved adding PasswordAuth to vagrant file from posinst * Added ubuntu 24.04 * Set version to 2.0.2 * Proper handle for missing configuration * Fixup use value of optional object * Add more vCPU/RAM to vagrant VM's + fix translations * Minor WS fixes, translations * Proper handler for Werification error * Make use of prompt parameter * Add max number of prompts * remove unused code, fir includes * Add Waiting status * Add check application status check --------- Co-authored-by: Madzik <m.w@linux.pl>
113 lines
3.2 KiB
C++
Executable File
113 lines
3.2 KiB
C++
Executable File
#include "gmock/gmock.h"
|
|
#include <gtest/gtest.h>
|
|
#include <memory_resource>
|
|
#include <string>
|
|
|
|
#include <rublon/utils.hpp>
|
|
|
|
using namespace rublon;
|
|
using namespace testing;
|
|
|
|
TEST(Utils, toBoolReturnsTrueWhenStringIsPassed) {
|
|
EXPECT_TRUE(conv::to_bool("TrUe"));
|
|
}
|
|
|
|
TEST(Utils, toBoolReturnsFalseWhenStringIsPassed) {
|
|
EXPECT_FALSE(conv::to_bool("False"));
|
|
}
|
|
|
|
std::string response = R"http(HTTP/2 200
|
|
date: Thu, 22 Jun 2023 13:24:58 GMT
|
|
content-type: application/json
|
|
server: nginx
|
|
cache-control: no-cache, private
|
|
x-rublon-signature: 1a01558bedaa2dd92ff659fb8ee3c65a89163d63e312fcb9b6f60463cce864d7
|
|
x-ratelimit-limit: 300
|
|
x-ratelimit-remaining: 299
|
|
|
|
{"status":"OK","result":{"tid":"2039132542F6465691BF8C41D7CC38C5","status":"pending","companyName":"rublon","applicationName":"Bartoszek_SSH","methods":["email","totp","qrcode","push"]}})http";
|
|
|
|
class LoggingAllocator : public std::pmr::memory_resource {
|
|
public:
|
|
int count{};
|
|
int bytes{};
|
|
|
|
void clear() {
|
|
count = 0;
|
|
bytes = 0;
|
|
}
|
|
// memory_resource interface
|
|
private:
|
|
void * do_allocate(std::size_t __bytes, std::size_t __alignment) override {
|
|
bytes += __bytes;
|
|
count++;
|
|
return std::pmr::get_default_resource()->allocate(__bytes, __alignment);
|
|
}
|
|
|
|
void do_deallocate(void * __p, std::size_t __bytes, std::size_t __alignment) override {
|
|
bytes -= __bytes;
|
|
count--;
|
|
std::pmr::get_default_resource()->deallocate(__p, __bytes, __alignment);
|
|
}
|
|
|
|
bool do_is_equal(const memory_resource & __other) const noexcept override {
|
|
return std::pmr::get_default_resource()->is_equal(__other);
|
|
}
|
|
};
|
|
|
|
TEST(Utils, responseParser) {
|
|
memory::MonotonicStackResource< 2048 > resource;
|
|
std::map<std::string, std::string> sut{};
|
|
rublon::details::headers(response, sut);
|
|
EXPECT_THAT(sut,
|
|
AllOf(Contains(Pair("date", "Thu, 22 Jun 2023 13:24:58 GMT")),
|
|
Contains(Pair("x-rublon-signature", "1a01558bedaa2dd92ff659fb8ee3c65a89163d63e312fcb9b6f60463cce864d7")),
|
|
Contains(Pair("x-ratelimit-remaining", "299"))));
|
|
}
|
|
|
|
class Memory : public testing::Test {
|
|
public:
|
|
// Test interface
|
|
protected:
|
|
void SetUp() override {
|
|
memory::set_default_resource(&alloc);
|
|
}
|
|
void TearDown() override {
|
|
memory::set_default_resource(std::pmr::get_default_resource());
|
|
}
|
|
|
|
LoggingAllocator alloc;
|
|
};
|
|
|
|
class X {};
|
|
|
|
TEST_F(Memory, setSetsProperResource) {
|
|
LoggingAllocator s;
|
|
memory::set_default_resource(&s);
|
|
EXPECT_EQ(&s, memory::default_resource());
|
|
}
|
|
|
|
TEST_F(Memory, stackResourceDoesNotUseHeapAtAll) {
|
|
memory::MonotonicStackResource< 1024 > mr;
|
|
std::pmr::string{"to large to fit in small buffer optimization", &mr};
|
|
|
|
EXPECT_EQ(alloc.count, 0);
|
|
}
|
|
|
|
TEST_F(Memory, heapResourceWillAllocate1kWhenAsk) {
|
|
memory::set_default_resource(&alloc);
|
|
memory::StrictMonotonic_1k_HeapResource mr;
|
|
std::pmr::string{"to large to fit in small buffer optimization", &mr};
|
|
|
|
EXPECT_EQ(alloc.count, 1);
|
|
EXPECT_EQ(alloc.bytes, 1024);
|
|
}
|
|
|
|
TEST_F(Memory, heapResourceWillAllocate8kWhenAsk) {
|
|
memory::StrictMonotonic_8k_HeapResource mr;
|
|
std::pmr::string{"to large to fit in small buffer optimization", &mr};
|
|
|
|
EXPECT_EQ(alloc.count, 1);
|
|
EXPECT_EQ(alloc.bytes, 8 * 1024);
|
|
}
|