-
Notifications
You must be signed in to change notification settings - Fork 3
Implement ActivityPub discovery endpoints #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+420
−3
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aceee50
Add webfinger query handling with default config
sij411 c09097d
Add response header and return response
sij411 82da624
Add mise run test command
sij411 0121411
Test WebFinger discovery responses
sij411 6278df4
Implement actor endpoint
sij411 11e7af0
Test local ActivityPub actor endpoint
sij411 7d67af1
Implement note endpoint
sij411 6cc594f
Test public Note endpoint
sij411 07be8f9
Fix hardcoded URL to suffix
sij411 0cc162c
Enable tower's util
sij411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Feder: A portable ActivityPub core for many runtimes. | ||
| // Copyright (C) 2026 Feder contributors | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, version 3. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use axum::{ | ||
| Json, | ||
| extract::{Path, State}, | ||
| http::{StatusCode, header}, | ||
| response::{IntoResponse, Response}, | ||
| }; | ||
|
|
||
| use crate::app::AppState; | ||
|
|
||
| pub async fn actor( | ||
| State(app_state): State<AppState>, | ||
| Path(username): Path<String>, | ||
| ) -> Result<Response, StatusCode> { | ||
| if username != app_state.username { | ||
| return Err(StatusCode::NOT_FOUND); | ||
| } | ||
| let local_actor = app_state.local_actor.clone(); | ||
|
|
||
| Ok(( | ||
| [(header::CONTENT_TYPE, "application/activity+json")], | ||
| Json(local_actor), | ||
| ) | ||
| .into_response()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use axum::{ | ||
| body::{Body, to_bytes}, | ||
| http::{Request, StatusCode, header}, | ||
| }; | ||
| use serde_json::Value; | ||
| use tower::ServiceExt; | ||
|
|
||
| use crate::{app::build_router, config::RuntimeConfig}; | ||
|
|
||
| #[tokio::test] | ||
| async fn returns_local_actor() { | ||
| let app = build_router(&RuntimeConfig::default_local()); | ||
|
|
||
| let response = app | ||
| .oneshot( | ||
| Request::builder() | ||
| .uri("/users/alice") | ||
| .body(Body::empty()) | ||
| .expect("valid request"), | ||
| ) | ||
| .await | ||
| .expect("response"); | ||
|
|
||
| assert_eq!(response.status(), StatusCode::OK); | ||
| assert_eq!( | ||
| response.headers().get(header::CONTENT_TYPE).unwrap(), | ||
| "application/activity+json" | ||
| ); | ||
|
|
||
| let body = to_bytes(response.into_body(), 2048) | ||
| .await | ||
| .expect("read response body"); | ||
| let json: Value = serde_json::from_slice(&body).expect("valid json"); | ||
|
|
||
| assert_eq!(json["@context"], "https://www.w3.org/ns/activitystreams"); | ||
| assert_eq!(json["type"], "Person"); | ||
| assert_eq!(json["id"], "http://127.0.0.1:3000/users/alice"); | ||
| assert_eq!(json["inbox"], "http://127.0.0.1:3000/users/alice/inbox"); | ||
| assert_eq!(json["outbox"], "http://127.0.0.1:3000/users/alice/outbox"); | ||
| assert_eq!(json["preferredUsername"], "alice"); | ||
| assert_eq!(json["name"], "alice"); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn rejects_unknown_actor() { | ||
| let app = build_router(&RuntimeConfig::default_local()); | ||
|
|
||
| let response = app | ||
| .oneshot( | ||
| Request::builder() | ||
| .uri("/users/bob") | ||
| .body(Body::empty()) | ||
| .expect("valid request"), | ||
| ) | ||
| .await | ||
| .expect("response"); | ||
|
|
||
| assert_eq!(response.status(), StatusCode::NOT_FOUND); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Feder: A portable ActivityPub core for many runtimes. | ||
| // Copyright (C) 2026 Feder contributors | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, version 3. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use axum::{ | ||
| Json, | ||
| extract::{Path, State}, | ||
| http::{StatusCode, header}, | ||
| response::{IntoResponse, Response}, | ||
| }; | ||
|
|
||
| use crate::app::AppState; | ||
|
|
||
| pub async fn note( | ||
| State(app_state): State<AppState>, | ||
| Path(id): Path<String>, | ||
| ) -> Result<Response, StatusCode> { | ||
| // TODO(#25): Replace this seeded preview note with durable runtime storage. | ||
| let expected_suffix = format!("/notes/{id}"); | ||
| let note = app_state | ||
| .notes | ||
| .iter() | ||
| .find(|note| note.id.as_str().ends_with(&expected_suffix)) | ||
| .cloned() | ||
| .ok_or(StatusCode::NOT_FOUND)?; | ||
|
|
||
| Ok(( | ||
| [(header::CONTENT_TYPE, "application/activity+json")], | ||
| Json(note), | ||
| ) | ||
| .into_response()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use axum::{ | ||
| body::{Body, to_bytes}, | ||
| http::{Request, StatusCode, header}, | ||
| }; | ||
| use serde_json::Value; | ||
| use tower::ServiceExt; | ||
|
|
||
| use crate::{app::build_router, config::RuntimeConfig}; | ||
|
|
||
| #[tokio::test] | ||
| async fn returns_public_note() { | ||
| let app = build_router(&RuntimeConfig::default_local()); | ||
|
|
||
| let response = app | ||
| .oneshot( | ||
| Request::builder() | ||
| .uri("/notes/1") | ||
| .body(Body::empty()) | ||
| .expect("valid request"), | ||
| ) | ||
| .await | ||
| .expect("response"); | ||
|
|
||
| assert_eq!(response.status(), StatusCode::OK); | ||
| assert_eq!( | ||
| response.headers().get(header::CONTENT_TYPE).unwrap(), | ||
| "application/activity+json" | ||
| ); | ||
|
|
||
| let body = to_bytes(response.into_body(), 2048) | ||
| .await | ||
| .expect("read response body"); | ||
| let json: Value = serde_json::from_slice(&body).expect("valid json"); | ||
|
|
||
| assert_eq!(json["@context"], "https://www.w3.org/ns/activitystreams"); | ||
| assert_eq!(json["type"], "Note"); | ||
| assert_eq!(json["id"], "http://127.0.0.1:3000/notes/1"); | ||
| assert_eq!(json["attributedTo"], "http://127.0.0.1:3000/users/alice"); | ||
| assert_eq!( | ||
| json["content"], | ||
| "Hello, World! This is Feder, a portable AP core for many runtimes." | ||
| ); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn rejects_unknown_note() { | ||
| let app = build_router(&RuntimeConfig::default_local()); | ||
|
|
||
| let response = app | ||
| .oneshot( | ||
| Request::builder() | ||
| .uri("/notes/missing") | ||
| .body(Body::empty()) | ||
| .expect("valid request"), | ||
| ) | ||
| .await | ||
| .expect("response"); | ||
|
|
||
| assert_eq!(response.status(), StatusCode::NOT_FOUND); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.