diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2020-01-07 21:45:53 +0100 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2020-01-07 21:45:53 +0100 |
commit | 436993e9d7f687f6f6a83ca7e2ec42dd289463ea (patch) | |
tree | 2bf2f71424b4bede33339b8ab0afb8226edbfe4e /test/libapt | |
parent | 01ff55f375b3d9e96b178d3a963d9e3d5ac5134b (diff) |
gtests: Fix netrc parser test regression from https-only changes
We missed that because the CI never ran GTests, because it did
not find the GTest library and failed silently (until the previous
commit).
Diffstat (limited to 'test/libapt')
-rw-r--r-- | test/libapt/authconf_test.cc | 81 |
1 files changed, 57 insertions, 24 deletions
diff --git a/test/libapt/authconf_test.cc b/test/libapt/authconf_test.cc index a7b2f2c98..04d54e9be 100644 --- a/test/libapt/authconf_test.cc +++ b/test/libapt/authconf_test.cc @@ -13,7 +13,7 @@ TEST(NetRCTest, Parsing) { FileFd fd; - URI U("http://file.not/open"); + URI U("https://file.not/open"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); @@ -38,8 +38,8 @@ machine example.com/bar password pass2 login user2 unknown token machine example.com/user login user machine example.netter login unused password firstentry -machine example.last/debian login debian password rules)apt"); - U = URI("http://example.net/foo"); +machine socks5h://example.last/debian login debian password rules)apt"); + U = URI("https://example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); @@ -47,7 +47,7 @@ machine example.last/debian login debian password rules)apt"); EXPECT_EQ("/foo", U.Path); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://user:pass@example.net/foo"); + U = URI("https://user:pass@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user", U.User); EXPECT_EQ("pass", U.Password); @@ -55,7 +55,7 @@ machine example.last/debian login debian password rules)apt"); EXPECT_EQ("/foo", U.Path); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.org:90/foo"); + U = URI("https://example.org:90/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("apt", U.User); EXPECT_EQ("apt", U.Password); @@ -64,55 +64,55 @@ machine example.last/debian login debian password rules)apt"); EXPECT_EQ("/foo", U.Path); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.org:8080/foo"); + U = URI("https://example.org:8080/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("example", U.User); EXPECT_EQ("foobar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net:42/foo"); + U = URI("https://example.net:42/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.org/foo"); + U = URI("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("anonymous", U.User); EXPECT_EQ("pass", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/apt"); + U = URI("https://example.com/apt"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/foo"); + U = URI("https://example.com/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user1", U.User); EXPECT_EQ("pass1", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/fooo"); + U = URI("https://example.com/fooo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user1", U.User); EXPECT_EQ("pass1", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/fo"); + U = URI("https://example.com/fo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/bar"); + U = URI("https://example.com/bar"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user2", U.User); EXPECT_EQ("pass2", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.com/user"); + U = URI("https://example.com/user"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("user", U.User); EXPECT_TRUE(U.Password.empty()); @@ -144,7 +144,7 @@ machin example.org login foo2 password bar machine2 example.org login foo3 password bar )apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); @@ -156,19 +156,19 @@ TEST(NetRCTest, BadFileEndsMachine) machine example.org login foo1 password bar machine)apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo1", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net/foo"); + U = URI("https://example.net/foo"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://foo:bar@example.net/foo"); + U = URI("https://foo:bar@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); @@ -180,19 +180,19 @@ TEST(NetRCTest, BadFileEndsLogin) machine example.org login foo1 password bar machine example.net login)apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo1", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net/foo"); + U = URI("https://example.net/foo"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://foo:bar@example.net/foo"); + U = URI("https://foo:bar@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); @@ -204,20 +204,53 @@ TEST(NetRCTest, BadFileEndsPassword) machine example.org login foo1 password bar machine example.net password)apt"); - URI U("http://example.org/foo"); + URI U("https://example.org/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo1", U.User); EXPECT_EQ("bar", U.Password); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://example.net/foo"); + U = URI("https://example.net/foo"); EXPECT_FALSE(MaybeAddAuth(fd, U)); EXPECT_TRUE(U.User.empty()); EXPECT_TRUE(U.Password.empty()); EXPECT_TRUE(fd.Seek(0)); - U = URI("http://foo:bar@example.net/foo"); + U = URI("https://foo:bar@example.net/foo"); EXPECT_TRUE(MaybeAddAuth(fd, U)); EXPECT_EQ("foo", U.User); EXPECT_EQ("bar", U.Password); } + +TEST(NetRCTest, MatchesOnlyHTTPS) +{ + FileFd fd; + createTemporaryFile("doublesignedfile", fd, nullptr, R"apt( +machine https.example login foo1 password bar +machine http://http.example login foo1 password bar +)apt"); + + URI U("https://https.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_EQ("foo1", U.User); + EXPECT_EQ("bar", U.Password); + + EXPECT_TRUE(fd.Seek(0)); + U = URI("http://https.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_TRUE(U.User.empty()); + EXPECT_TRUE(U.Password.empty()); + + EXPECT_TRUE(fd.Seek(0)); + U = URI("http://http.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_EQ("foo1", U.User); + EXPECT_EQ("bar", U.Password); + + EXPECT_TRUE(fd.Seek(0)); + U = URI("https://http.example/foo"); + EXPECT_TRUE(MaybeAddAuth(fd, U)); + EXPECT_TRUE(U.User.empty()); + EXPECT_TRUE(U.Password.empty()); + +} |