diff options
Diffstat (limited to 'test/buildtool/graph_traverser')
4 files changed, 99 insertions, 42 deletions
diff --git a/test/buildtool/graph_traverser/TARGETS b/test/buildtool/graph_traverser/TARGETS index 937f3b04..c67ded03 100644 --- a/test/buildtool/graph_traverser/TARGETS +++ b/test/buildtool/graph_traverser/TARGETS @@ -5,6 +5,7 @@ , "deps": [ ["@", "catch2", "", "catch2"] , ["@", "json", "", "json"] + , ["@", "src", "src/buildtool/auth", "auth"] , ["@", "src", "src/buildtool/common", "common"] , ["@", "src", "src/buildtool/execution_api/local", "config"] , ["@", "src", "src/buildtool/file_system", "file_system_manager"] @@ -40,6 +41,7 @@ [ "graph_traverser_tests" , ["@", "catch2", "", "catch2"] , ["utils", "catch-main-remote-execution"] + , ["@", "src", "src/buildtool/auth", "auth"] ] , "stage": ["test", "buildtool", "graph_traverser"] } diff --git a/test/buildtool/graph_traverser/graph_traverser.test.hpp b/test/buildtool/graph_traverser/graph_traverser.test.hpp index 3f235087..7d23dcd5 100644 --- a/test/buildtool/graph_traverser/graph_traverser.test.hpp +++ b/test/buildtool/graph_traverser/graph_traverser.test.hpp @@ -18,6 +18,7 @@ #include <chrono> #include <cstdlib> #include <filesystem> +#include <optional> #include <sstream> #include <string> #include <thread> @@ -26,6 +27,7 @@ #include "catch2/catch_test_macros.hpp" #include "nlohmann/json.hpp" +#include "src/buildtool/auth/authentication.hpp" #include "src/buildtool/common/statistics.hpp" #include "src/buildtool/execution_api/common/api_bundle.hpp" #include "src/buildtool/execution_api/local/config.hpp" @@ -150,6 +152,7 @@ inline void SetLauncher() { } // namespace [[maybe_unused]] static void TestHelloWorldCopyMessage( + Auth::TLS const* auth, bool is_hermetic = true) { TestProject p("hello_world_copy_message"); @@ -157,8 +160,8 @@ inline void SetLauncher() { auto const clargs = p.CmdLineArgs(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -185,8 +188,8 @@ inline void SetLauncher() { SECTION("Executable is retrieved as executable") { auto const clargs_exec = p.CmdLineArgs("_entry_points_get_executable"); - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser const gt_get_exec{ clargs_exec.gtargs, p.GetRepoConfig(), @@ -214,15 +217,16 @@ inline void SetLauncher() { } } -[[maybe_unused]] static void TestCopyLocalFile(bool is_hermetic = true) { +[[maybe_unused]] static void TestCopyLocalFile(Auth::TLS const* auth, + bool is_hermetic = true) { TestProject p("copy_local_file"); SetLauncher(); auto const clargs = p.CmdLineArgs(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -245,6 +249,7 @@ inline void SetLauncher() { } [[maybe_unused]] static void TestSequencePrinterBuildLibraryOnly( + Auth::TLS const* auth, bool is_hermetic = true) { TestProject p("sequence_printer_build_library_only"); @@ -252,8 +257,8 @@ inline void SetLauncher() { auto const clargs = p.CmdLineArgs(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser const gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -296,6 +301,7 @@ inline void SetLauncher() { } [[maybe_unused]] static void TestHelloWorldWithKnownSource( + Auth::TLS const* auth, bool is_hermetic = true) { TestProject full_hello_world("hello_world_copy_message"); @@ -305,6 +311,7 @@ inline void SetLauncher() { Statistics stats{}; Progress progress{}; ApiBundle const apis{full_hello_world.GetRepoConfig(), + auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser const gt_upload{clargs_update_cpp.gtargs, full_hello_world.GetRepoConfig(), @@ -353,15 +360,16 @@ inline void SetLauncher() { } } -static void TestBlobsUploadedAndUsed(bool is_hermetic = true) { +static void TestBlobsUploadedAndUsed(Auth::TLS const* auth, + bool is_hermetic = true) { TestProject p("use_uploaded_blobs"); auto const clargs = p.CmdLineArgs(); SetLauncher(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -391,15 +399,16 @@ static void TestBlobsUploadedAndUsed(bool is_hermetic = true) { } } -static void TestEnvironmentVariablesSetAndUsed(bool is_hermetic = true) { +static void TestEnvironmentVariablesSetAndUsed(Auth::TLS const* auth, + bool is_hermetic = true) { TestProject p("use_env_variables"); auto const clargs = p.CmdLineArgs(); SetLauncher(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -429,15 +438,15 @@ static void TestEnvironmentVariablesSetAndUsed(bool is_hermetic = true) { } } -static void TestTreesUsed(bool is_hermetic = true) { +static void TestTreesUsed(Auth::TLS const* auth, bool is_hermetic = true) { TestProject p("use_trees"); auto const clargs = p.CmdLineArgs(); SetLauncher(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -467,15 +476,16 @@ static void TestTreesUsed(bool is_hermetic = true) { } } -static void TestNestedTreesUsed(bool is_hermetic = true) { +static void TestNestedTreesUsed(Auth::TLS const* auth, + bool is_hermetic = true) { TestProject p("use_nested_trees"); auto const clargs = p.CmdLineArgs(); SetLauncher(); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; GraphTraverser gt{clargs.gtargs, p.GetRepoConfig(), RemoteExecutionConfig::PlatformProperties(), @@ -505,13 +515,14 @@ static void TestNestedTreesUsed(bool is_hermetic = true) { } } -static void TestFlakyHelloWorldDetected(bool /*is_hermetic*/ = true) { +static void TestFlakyHelloWorldDetected(Auth::TLS const* auth, + bool /*is_hermetic*/ = true) { TestProject p("flaky_hello_world"); Statistics stats{}; Progress progress{}; - ApiBundle const apis{p.GetRepoConfig(), - RemoteExecutionConfig::RemoteAddress()}; + ApiBundle const apis{ + p.GetRepoConfig(), auth, RemoteExecutionConfig::RemoteAddress()}; { SetLauncher(); diff --git a/test/buildtool/graph_traverser/graph_traverser_local.test.cpp b/test/buildtool/graph_traverser/graph_traverser_local.test.cpp index bfb8a2e0..64d7189b 100644 --- a/test/buildtool/graph_traverser/graph_traverser_local.test.cpp +++ b/test/buildtool/graph_traverser/graph_traverser_local.test.cpp @@ -19,53 +19,53 @@ TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Output created when entry point is local artifact", "[graph_traverser]") { - TestCopyLocalFile(); + TestCopyLocalFile(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Output created and contents are correct", "[graph_traverser]") { - TestHelloWorldCopyMessage(); + TestHelloWorldCopyMessage(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Actions are not re-run", "[graph_traverser]") { - TestSequencePrinterBuildLibraryOnly(); + TestSequencePrinterBuildLibraryOnly(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: KNOWN artifact", "[graph_traverser]") { - TestHelloWorldWithKnownSource(); + TestHelloWorldWithKnownSource(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Blobs uploaded and correctly used", "[graph_traverser]") { - TestBlobsUploadedAndUsed(); + TestBlobsUploadedAndUsed(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Environment variables are set and used", "[graph_traverser]") { - TestEnvironmentVariablesSetAndUsed(); + TestEnvironmentVariablesSetAndUsed(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Trees correctly used", "[graph_traverser]") { - TestTreesUsed(); + TestTreesUsed(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Nested trees correctly used", "[graph_traverser]") { - TestNestedTreesUsed(); + TestNestedTreesUsed(/*auth=*/nullptr); } TEST_CASE_METHOD(HermeticLocalTestFixture, "Local: Detect flaky actions", "[graph_traverser]") { - TestFlakyHelloWorldDetected(); + TestFlakyHelloWorldDetected(/*auth=*/nullptr); } diff --git a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp index 48867d16..e33d5d27 100644 --- a/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp +++ b/test/buildtool/graph_traverser/graph_traverser_remote.test.cpp @@ -12,44 +12,88 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include <optional> + #include "catch2/catch_test_macros.hpp" +#include "src/buildtool/auth/authentication.hpp" #include "test/buildtool/graph_traverser/graph_traverser.test.hpp" TEST_CASE("Remote: Output created and contents are correct", "[graph_traverser]") { - TestHelloWorldCopyMessage(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestHelloWorldCopyMessage(auth ? &*auth : nullptr, + false /* not hermetic */); } TEST_CASE("Remote: Output created when entry point is local artifact", "[graph_traverser]") { - TestCopyLocalFile(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestCopyLocalFile(auth ? &*auth : nullptr, false /* not hermetic */); } TEST_CASE("Remote: Actions are not re-run", "[graph_traverser]") { - TestSequencePrinterBuildLibraryOnly(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestSequencePrinterBuildLibraryOnly(auth ? &*auth : nullptr, + false /* not hermetic */); } TEST_CASE("Remote: KNOWN artifact", "[graph_traverser]") { - TestHelloWorldWithKnownSource(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestHelloWorldWithKnownSource(auth ? &*auth : nullptr, + false /* not hermetic */); } TEST_CASE("Remote: Blobs uploaded and correctly used", "[graph_traverser]") { - TestBlobsUploadedAndUsed(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestBlobsUploadedAndUsed(auth ? &*auth : nullptr, false /* not hermetic */); } TEST_CASE("Remote: Environment variables are set and used", "[graph_traverser]") { - TestEnvironmentVariablesSetAndUsed(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestEnvironmentVariablesSetAndUsed(auth ? &*auth : nullptr, + false /* not hermetic */); } TEST_CASE("Remote: Trees correctly used", "[graph_traverser]") { - TestTreesUsed(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestTreesUsed(auth ? &*auth : nullptr, false /* not hermetic */); } TEST_CASE("Remote: Nested trees correctly used", "[graph_traverser]") { - TestNestedTreesUsed(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestNestedTreesUsed(auth ? &*auth : nullptr, false /* not hermetic */); } TEST_CASE("Remote: Detect flaky actions", "[graph_traverser]") { - TestFlakyHelloWorldDetected(false /* not hermetic */); + std::optional<Auth::TLS> auth = {}; + if (Auth::Instance().GetAuthMethod() == AuthMethod::kTLS) { + auth = Auth::TLS::Instance(); + } + TestFlakyHelloWorldDetected(auth ? &*auth : nullptr, + false /* not hermetic */); } |