]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Add speed tests for the credentials class
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 31 Mar 2021 07:52:57 +0000 (09:52 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 16 Sep 2021 12:12:27 +0000 (14:12 +0200)
pdns/Makefile.am
pdns/speedtest.cc

index 5982b705723624d65d763d1768c1ed4dd8cd5c18..2eed01ecd6c564edd7ae032e60f51852d256100f 100644 (file)
@@ -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
index 34715eac4c76d184f3f1e7ba567c09f6b0da3fed..50f40cb1199005707a4765603801dd73dc3fda53 100644 (file)
@@ -1,6 +1,7 @@
 #include "config.h"
 #include <boost/format.hpp>
 #include <boost/container/string.hpp>
+#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();