From: Remi Gacogne Date: Wed, 31 Mar 2021 07:52:57 +0000 (+0200) Subject: auth: Add speed tests for the credentials class X-Git-Tag: dnsdist-1.7.0-alpha1~12^2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11227477256ca8651dbfd34b3b0afd0eb916eaec;p=thirdparty%2Fpdns.git auth: Add speed tests for the credentials class --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 5982b70572..2eed01ecd6 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -917,6 +917,7 @@ endif speedtest_SOURCES = \ base32.cc \ base64.cc base64.hh \ + credentials.cc credentials.hh \ dnslabeltext.cc \ dnsname.cc dnsname.hh \ dnsparser.cc dnsparser.hh \ @@ -1426,6 +1427,7 @@ endif if LIBSODIUM testrunner_SOURCES += sodiumsigners.cc testrunner_LDADD += $(LIBSODIUM_LIBS) +speedtest_LDADD += $(LIBSODIUM_LIBS) endif if LIBDECAF diff --git a/pdns/speedtest.cc b/pdns/speedtest.cc index 34715eac4c..50f40cb119 100644 --- a/pdns/speedtest.cc +++ b/pdns/speedtest.cc @@ -1,6 +1,7 @@ #include "config.h" #include #include +#include "credentials.hh" #include "dnsparser.hh" #include "sstuff.hh" #include "misc.hh" @@ -1028,6 +1029,45 @@ private: bool d_contended; }; +struct CredentialsHashTest +{ + explicit CredentialsHashTest() {} + + string getName() const + { + return "Credentials hashing test"; + } + + void operator()() const + { + hashPassword(d_password); + } + +private: + const std::string d_password{"test password"}; +}; + +struct CredentialsVerifyTest +{ + explicit CredentialsVerifyTest() { + d_hashed = hashPassword(d_password); + } + + string getName() const + { + return "Credentials verification test"; + } + + void operator()() const + { + verifyPassword(d_hashed, d_password); + } + +private: + std::string d_hashed; + const std::string d_password{"test password"}; +}; + int main(int argc, char** argv) try { @@ -1146,6 +1186,11 @@ try doRun(NSEC3HashTest(150, "ABCDABCDABCDABCDABCDABCDABCDABCD")); doRun(NSEC3HashTest(500, "ABCDABCDABCDABCDABCDABCDABCDABCD")); +#ifdef HAVE_LIBSODIUM + doRun(CredentialsHashTest()); + doRun(CredentialsVerifyTest()); +#endif + #ifndef RECURSOR S.doRings();