V2 removal and _internal rerouting (#770)

* deleteed v3 exclusive routes

* moved routes around

* fixed linkage that movement broke

* initial merge errors

* fixes
This commit is contained in:
Wyatt Verchere
2023-12-01 10:02:11 -08:00
committed by GitHub
parent 4bbc57b0dc
commit 2d92b08404
25 changed files with 93 additions and 899 deletions

View File

@@ -41,7 +41,7 @@ impl Api for ApiV3 {
async fn reset_search_index(&self) -> ServiceResponse {
let req = actix_web::test::TestRequest::post()
.uri("/v3/admin/_force_reindex")
.uri("/_internal/admin/_force_reindex")
.append_header((
"Modrinth-Admin",
dotenvy::var("LABRINTH_ADMIN_KEY").unwrap(),

View File

@@ -55,7 +55,7 @@ impl ApiV3 {
pub async fn oauth_accept(&self, flow: &str, pat: &str) -> ServiceResponse {
self.call(
TestRequest::post()
.uri("/v3/oauth/accept")
.uri("/_internal/oauth/accept")
.append_header((AUTHORIZATION, pat))
.set_json(RespondToOAuthClientScopes {
flow: flow.to_string(),
@@ -68,7 +68,7 @@ impl ApiV3 {
pub async fn oauth_reject(&self, flow: &str, pat: &str) -> ServiceResponse {
self.call(
TestRequest::post()
.uri("/v3/oauth/reject")
.uri("/_internal/oauth/reject")
.append_header((AUTHORIZATION, pat))
.set_json(RespondToOAuthClientScopes {
flow: flow.to_string(),
@@ -87,7 +87,7 @@ impl ApiV3 {
) -> ServiceResponse {
self.call(
TestRequest::post()
.uri("/v3/oauth/token")
.uri("/_internal/oauth/token")
.append_header((AUTHORIZATION, client_secret))
.set_form(TokenRequest {
grant_type: "authorization_code".to_string(),
@@ -108,7 +108,7 @@ pub fn generate_authorize_uri(
state: Option<&str>,
) -> String {
format!(
"/v3/oauth/authorize?client_id={}{}{}{}",
"/_internal/oauth/authorize?client_id={}{}{}{}",
urlencoding::encode(client_id),
optional_query_param("redirect_uri", redirect_uri),
optional_query_param("scope", scope),

View File

@@ -27,7 +27,7 @@ impl ApiV3 {
) -> ServiceResponse {
let max_scopes = max_scopes.bits();
let req = TestRequest::post()
.uri("/v3/oauth/app")
.uri("/_internal/oauth/app")
.append_header((AUTHORIZATION, pat))
.set_json(json!({
"name": name,
@@ -52,7 +52,7 @@ impl ApiV3 {
pub async fn get_oauth_client(&self, client_id: String, pat: &str) -> ServiceResponse {
let req = TestRequest::get()
.uri(&format!("/v3/oauth/app/{}", client_id))
.uri(&format!("/_internal/oauth/app/{}", client_id))
.append_header((AUTHORIZATION, pat))
.to_request();
@@ -66,7 +66,10 @@ impl ApiV3 {
pat: &str,
) -> ServiceResponse {
let req = TestRequest::patch()
.uri(&format!("/v3/oauth/app/{}", urlencoding::encode(client_id)))
.uri(&format!(
"/_internal/oauth/app/{}",
urlencoding::encode(client_id)
))
.set_json(edit)
.append_header((AUTHORIZATION, pat))
.to_request();
@@ -76,7 +79,7 @@ impl ApiV3 {
pub async fn delete_oauth_client(&self, client_id: &str, pat: &str) -> ServiceResponse {
let req = TestRequest::delete()
.uri(&format!("/v3/oauth/app/{}", client_id))
.uri(&format!("/_internal/oauth/app/{}", client_id))
.append_header((AUTHORIZATION, pat))
.to_request();
@@ -86,7 +89,7 @@ impl ApiV3 {
pub async fn revoke_oauth_authorization(&self, client_id: &str, pat: &str) -> ServiceResponse {
let req = TestRequest::delete()
.uri(&format!(
"/v3/oauth/authorizations?client_id={}",
"/_internal/oauth/authorizations?client_id={}",
urlencoding::encode(client_id)
))
.append_header((AUTHORIZATION, pat))
@@ -96,7 +99,7 @@ impl ApiV3 {
pub async fn get_user_oauth_authorizations(&self, pat: &str) -> Vec<OAuthClientAuthorization> {
let req = TestRequest::get()
.uri("/v3/oauth/authorizations")
.uri("/_internal/oauth/authorizations")
.append_header((AUTHORIZATION, pat))
.to_request();
let resp = self.call(req).await;

View File

@@ -19,7 +19,7 @@ pub async fn pat_full_test() {
with_test_environment_all(None, |test_env| async move {
// Create a PAT for a full test
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE, // Collection create as an easily tested example
@@ -43,7 +43,7 @@ pub async fn pat_full_test() {
// Get PAT again
let req = test::TestRequest::get()
.append_header(("Authorization", USER_USER_PAT))
.uri("/v3/pat")
.uri("/_internal/pat")
.to_request();
let resp = test_env.call(req).await;
assert_eq!(resp.status().as_u16(), 200);
@@ -75,7 +75,7 @@ pub async fn pat_full_test() {
// Change scopes and test again
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": 0,
@@ -87,7 +87,7 @@ pub async fn pat_full_test() {
// Change scopes back, and set expiry to the past, and test again
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE,
@@ -103,7 +103,7 @@ pub async fn pat_full_test() {
// Change everything back to normal and test again
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"expires": Utc::now() + Duration::days(1), // no longer expired!
@@ -115,7 +115,7 @@ pub async fn pat_full_test() {
// Patching to a bad expiry should fail
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"expires": Utc::now() - Duration::days(1), // Past
@@ -132,7 +132,7 @@ pub async fn pat_full_test() {
}
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": scope.bits(),
@@ -148,7 +148,7 @@ pub async fn pat_full_test() {
// Delete PAT
let req = test::TestRequest::delete()
.append_header(("Authorization", USER_USER_PAT))
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.to_request();
let resp = test_env.call(req).await;
assert_eq!(resp.status().as_u16(), 204);
@@ -162,7 +162,7 @@ pub async fn bad_pats() {
with_test_environment_all(None, |test_env| async move {
// Creating a PAT with no name should fail
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE, // Collection create as an easily tested example
@@ -175,7 +175,7 @@ pub async fn bad_pats() {
// Name too short or too long should fail
for name in ["n", "this_name_is_too_long".repeat(16).as_str()] {
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"name": name,
@@ -189,7 +189,7 @@ pub async fn bad_pats() {
// Creating a PAT with an expiry in the past should fail
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE, // Collection create as an easily tested example
@@ -207,7 +207,7 @@ pub async fn bad_pats() {
continue;
}
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": scope.bits(),
@@ -224,7 +224,7 @@ pub async fn bad_pats() {
// Create a 'good' PAT for patching
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE,
@@ -240,7 +240,7 @@ pub async fn bad_pats() {
// Patching to a bad name should fail
for name in ["n", "this_name_is_too_long".repeat(16).as_str()] {
let req = test::TestRequest::post()
.uri("/v3/pat")
.uri("/_internal/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"name": name,
@@ -252,7 +252,7 @@ pub async fn bad_pats() {
// Patching to a bad expiry should fail
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"expires": Utc::now() - Duration::days(1), // Past
@@ -269,7 +269,7 @@ pub async fn bad_pats() {
}
let req = test::TestRequest::patch()
.uri(&format!("/v3/pat/{}", id))
.uri(&format!("/_internal/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": scope.bits(),

View File

@@ -1017,11 +1017,13 @@ pub async fn pat_scopes() {
// Pat create
let pat_create = Scopes::PAT_CREATE;
let req_gen = || {
test::TestRequest::post().uri("/v3/pat").set_json(json!({
"scopes": 1,
"name": "test_pat_scopes Name",
"expires": Utc::now() + Duration::days(1),
}))
test::TestRequest::post()
.uri("/_internal/pat")
.set_json(json!({
"scopes": 1,
"name": "test_pat_scopes Name",
"expires": Utc::now() + Duration::days(1),
}))
};
let (_, success) = ScopeTest::new(&test_env)
.test(req_gen, pat_create)
@@ -1033,7 +1035,7 @@ pub async fn pat_scopes() {
let pat_write = Scopes::PAT_WRITE;
let req_gen = || {
test::TestRequest::patch()
.uri(&format!("/v3/pat/{pat_id}"))
.uri(&format!("/_internal/pat/{pat_id}"))
.set_json(json!({}))
};
ScopeTest::new(&test_env)
@@ -1043,7 +1045,7 @@ pub async fn pat_scopes() {
// Pat read
let pat_read = Scopes::PAT_READ;
let req_gen = || test::TestRequest::get().uri("/v3/pat");
let req_gen = || test::TestRequest::get().uri("/_internal/pat");
ScopeTest::new(&test_env)
.test(req_gen, pat_read)
.await
@@ -1051,7 +1053,7 @@ pub async fn pat_scopes() {
// Pat delete
let pat_delete = Scopes::PAT_DELETE;
let req_gen = || test::TestRequest::delete().uri(&format!("/v3/pat/{pat_id}"));
let req_gen = || test::TestRequest::delete().uri(&format!("/_internal/pat/{pat_id}"));
ScopeTest::new(&test_env)
.test(req_gen, pat_delete)
.await