mirror of
https://github.com/NixOS/nix.git
synced 2025-11-30 22:20:59 +01:00
feat: test and document access-token prefix support
This commit is contained in:
parent
69c7b42d28
commit
a9f4d73d3e
5 changed files with 89 additions and 4 deletions
79
src/libfetchers-tests/access-tokens.cc
Normal file
79
src/libfetchers-tests/access-tokens.cc
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "fetchers.hh"
|
||||
#include "fetch-settings.hh"
|
||||
#include "json-utils.hh"
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "tests/characterization.hh"
|
||||
|
||||
namespace nix::fetchers {
|
||||
|
||||
using nlohmann::json;
|
||||
|
||||
class AccessKeysTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
void SetUp() override {
|
||||
experimentalFeatureSettings.experimentalFeatures.get().insert(Xp::Flakes);
|
||||
}
|
||||
void TearDown() override { }
|
||||
};
|
||||
|
||||
TEST_F(AccessKeysTest, singleGitHub)
|
||||
{
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"github.com","token"});
|
||||
auto i = Input::fromURL(fetchSettings, "github:a/b");
|
||||
|
||||
auto token = i.scheme->getAccessToken(fetchSettings, "github.com", "github.com/a/b");
|
||||
ASSERT_EQ(token,"token");
|
||||
}
|
||||
|
||||
TEST_F(AccessKeysTest, repoGitHub)
|
||||
{
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"github.com","token"});
|
||||
fetchSettings.accessTokens.get().insert({"github.com/a/b","another_token"});
|
||||
fetchSettings.accessTokens.get().insert({"github.com/a/c","yet_another_token"});
|
||||
auto i = Input::fromURL(fetchSettings, "github:a/a");
|
||||
|
||||
auto token = i.scheme->getAccessToken(fetchSettings, "github.com", "github.com/a/a");
|
||||
ASSERT_EQ(token,"token");
|
||||
|
||||
token = i.scheme->getAccessToken(fetchSettings, "github.com", "github.com/a/b");
|
||||
ASSERT_EQ(token,"another_token");
|
||||
|
||||
token = i.scheme->getAccessToken(fetchSettings, "github.com", "github.com/a/c");
|
||||
ASSERT_EQ(token,"yet_another_token");
|
||||
}
|
||||
|
||||
TEST_F(AccessKeysTest, multipleGitLab)
|
||||
{
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"gitlab.com","token"});
|
||||
fetchSettings.accessTokens.get().insert({"gitlab.com/a/b","another_token"});
|
||||
auto i = Input::fromURL(fetchSettings, "gitlab:a/b");
|
||||
|
||||
auto token = i.scheme->getAccessToken(fetchSettings, "gitlab.com", "gitlab.com/a/b");
|
||||
ASSERT_EQ(token,"another_token");
|
||||
|
||||
token = i.scheme->getAccessToken(fetchSettings, "gitlab.com", "gitlab.com/a/c");
|
||||
ASSERT_EQ(token,"token");
|
||||
}
|
||||
|
||||
TEST_F(AccessKeysTest, multipleSourceHut)
|
||||
{
|
||||
fetchers::Settings fetchSettings = fetchers::Settings{};
|
||||
fetchSettings.accessTokens.get().insert({"git.sr.ht","token"});
|
||||
fetchSettings.accessTokens.get().insert({"git.sr.ht/~a/b","another_token"});
|
||||
auto i = Input::fromURL(fetchSettings, "sourcehut:a/b");
|
||||
|
||||
auto token = i.scheme->getAccessToken(fetchSettings, "git.sr.ht", "git.sr.ht/~a/b");
|
||||
ASSERT_EQ(token,"another_token");
|
||||
|
||||
token = i.scheme->getAccessToken(fetchSettings, "git.sr.ht", "git.sr.ht/~a/c");
|
||||
ASSERT_EQ(token,"token");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -44,6 +44,7 @@ subdir('nix-meson-build-support/common')
|
|||
|
||||
sources = files(
|
||||
'public-key.cc',
|
||||
'access-tokens.cc',
|
||||
)
|
||||
|
||||
include_dirs = [include_directories('.')]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue