File: assert_pubkeyalgo_test.cc

package info (click to toggle)
apt 3.1.13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,764 kB
  • sloc: cpp: 71,085; sh: 31,750; xml: 5,553; perl: 217; python: 197; ansic: 191; makefile: 41
file content (56 lines) | stat: -rw-r--r-- 1,728 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
#include <config.h>

#include <apt-pkg/error.h>
#include <apt-pkg/gpgv.h>

#include "common.h"

TEST(AssertPubKeyAlgo_Test, test)
{
   EXPECT_TRUE(IsAssertedPubKeyAlgo("rsa2048", ">=rsa2048"));
   _error->DumpErrors();
   EXPECT_TRUE(_error->empty());

   EXPECT_TRUE(IsAssertedPubKeyAlgo("rsa2048", "another,>=rsa2048"));
   EXPECT_TRUE(_error->empty());

   EXPECT_FALSE(IsAssertedPubKeyAlgo("rsa2048", ">=rsa2049"));
   EXPECT_TRUE(_error->empty());

   EXPECT_TRUE(IsAssertedPubKeyAlgo("ed25519", ">=rsa2048,ed25519"));
   EXPECT_TRUE(_error->empty());
}

TEST(AssertPubKeyAlgo_Test, CanOnlyCompareRSA)
{
   std::string msg;
   EXPECT_FALSE(IsAssertedPubKeyAlgo("ed25519", ">=ed25519"));
   EXPECT_TRUE(_error->PopMessage(msg));
   EXPECT_EQ("Unrecognized public key specification '>=ed25519' in option >=ed25519", msg);
   EXPECT_TRUE(_error->empty());
}

TEST(AssertPubKeyAlgo_Test, EmptyOption)
{
   std::string msg;
   EXPECT_FALSE(IsAssertedPubKeyAlgo("ed25519", ""));
   EXPECT_TRUE(_error->empty());

   EXPECT_FALSE(IsAssertedPubKeyAlgo("ed25519", ","));
   EXPECT_TRUE(_error->PopMessage(msg));
   EXPECT_EQ("Empty item in public key assertion string option ,", msg);
   EXPECT_TRUE(_error->empty());

   EXPECT_FALSE(IsAssertedPubKeyAlgo("ed25519", "moo,"));
   EXPECT_TRUE(_error->empty());

   EXPECT_FALSE(IsAssertedPubKeyAlgo("ed25519", "moo,,"));
   EXPECT_TRUE(_error->PopMessage(msg));
   EXPECT_EQ("Empty item in public key assertion string option moo,,", msg);
   EXPECT_TRUE(_error->empty());

   EXPECT_FALSE(IsAssertedPubKeyAlgo("ed25519", ",moo"));
   EXPECT_TRUE(_error->PopMessage(msg));
   EXPECT_EQ("Empty item in public key assertion string option ,moo", msg);
   EXPECT_TRUE(_error->empty());
}