Files
AstralRinth/apps/labrinth/tests/v2/scopes.rs
Josiah Glosson 650ab71a83 Commonized networking (#3310)
* Fix not being able to connect to local friends socket

* Start basic work on tunneling protocol and move some code into a common crate

* Commonize message serialization logic

* Serialize Base62Ids as u64 when human-readability is not required

* Move ActiveSockets tuple into struct

* Make CI run when rust-common is updated

CI is currently broken for labrinth, however

* Fix theseus-release.yml to reference itself correctly

* Implement Labrinth side of tunneling

* Implement non-friend part of theseus tunneling

* Implement client-side except for socket loop

* Implement the socket loop

Doesn't work though. Debugging time!

* Fix config.rs

* Fix deadlock in labrinth socket handling

* Update dockerfile

* switch to workspace prepare at root level

* Wait for connection before tunneling in playground

* Move rust-common into labrinth

* Remove rust-common references from Actions

* Revert "Update dockerfile"

This reverts commit 3caad59bb474ce425d0b8928d7cee7ae1a5011bd.

* Fix Docker build

* Rebuild Theseus if common code changes

* Allow multiple connections from the same user

* Fix test building

* Move FriendSocketListening and FriendSocketStoppedListening to non-panicking TODO for now

* Make message_serialization macro take varargs for binary messages

* Improve syntax of message_serialization macro

* Remove the ability to connect to a virtual socket, and disable the ability to listen on one

* Allow the app to compile without running labrinth

* Clippy fix

* Update Rust and Clippy fix again

---------

Co-authored-by: Jai A <jaiagr+gpg@pm.me>
2025-02-28 10:52:47 -08:00

91 lines
3.4 KiB
Rust

use crate::common::api_common::ApiProject;
use crate::common::api_common::ApiVersion;
use crate::common::api_v2::request_data::get_public_project_creation_data;
use crate::common::api_v2::ApiV2;
use crate::common::dummy_data::TestFile;
use crate::common::environment::with_test_environment;
use crate::common::environment::TestEnvironment;
use crate::common::scopes::ScopeTest;
use labrinth::common::ids::base62_impl::parse_base62;
use labrinth::models::pats::Scopes;
use labrinth::models::projects::ProjectId;
// Project version creation scopes
#[actix_rt::test]
pub async fn project_version_create_scopes() {
with_test_environment(
None,
|test_env: TestEnvironment<ApiV2>| async move {
let api = &test_env.api;
// Create project
let create_project = Scopes::PROJECT_CREATE;
let req_gen = |pat: Option<String>| async move {
let creation_data = get_public_project_creation_data(
"demo",
Some(TestFile::BasicMod),
None,
);
api.create_project(creation_data, pat.as_deref()).await
};
let (_, success) = ScopeTest::new(&test_env)
.test(req_gen, create_project)
.await
.unwrap();
let project_id = success["id"].as_str().unwrap();
let project_id = ProjectId(parse_base62(project_id).unwrap());
// Add version to project
let create_version = Scopes::VERSION_CREATE;
let req_gen = |pat: Option<String>| async move {
api.add_public_version(
project_id,
"1.2.3.4",
TestFile::BasicModDifferent,
None,
None,
pat.as_deref(),
)
.await
};
ScopeTest::new(&test_env)
.test(req_gen, create_version)
.await
.unwrap();
},
)
.await;
}
#[actix_rt::test]
pub async fn project_version_reads_scopes() {
with_test_environment(
None,
|_test_env: TestEnvironment<ApiV2>| async move {
// let api = &test_env.api;
// let beta_file_hash = &test_env.dummy.project_beta.file_hash;
// let read_version = Scopes::VERSION_READ;
// Update individual version file
// TODO: This scope currently fails still as the 'version' field of QueryProject only allows public versions.
// TODO: This will be fixed when the 'extracts_versions' PR is merged.
// let req_gen = |pat : Option<String>| async move {
// api.update_individual_files("sha1", vec![
// FileUpdateData {
// hash: beta_file_hash.clone(),
// loaders: None,
// game_versions: None,
// version_types: None
// }
// ], pat.as_deref())
// .await
// };
// let (failure, success) = ScopeTest::new(&test_env).with_failure_code(200).test(req_gen, read_version).await.unwrap();
// assert!(!failure.as_object().unwrap().contains_key(beta_file_hash));
// assert!(success.as_object().unwrap().contains_key(beta_file_hash));
},
)
.await;
}