Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Larry
pleroma
Commits
1dd767b8
Commit
1dd767b8
authored
4 years ago
by
Maksim
Browse files
Options
Downloads
Patches
Plain Diff
Include port in host for signatures
parent
3f65f2ea
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/web/activity_pub/publisher.ex
+15
-5
15 additions, 5 deletions
lib/pleroma/web/activity_pub/publisher.ex
test/web/activity_pub/publisher_test.exs
+33
-1
33 additions, 1 deletion
test/web/activity_pub/publisher_test.exs
with
48 additions
and
6 deletions
lib/pleroma/web/activity_pub/publisher.ex
+
15
−
5
View file @
1dd767b8
...
...
@@ -49,7 +49,8 @@ def is_representable?(%Activity{} = activity) do
"""
def
publish_one
(%{
inbox:
inbox
,
json:
json
,
actor:
%
User
{}
=
actor
,
id:
id
}
=
params
)
do
Logger
.
debug
(
"Federating
#{
id
}
to
#{
inbox
}
"
)
%{
host:
host
,
path:
path
}
=
URI
.
parse
(
inbox
)
uri
=
URI
.
parse
(
inbox
)
digest
=
"SHA-256="
<>
(
:crypto
.
hash
(
:sha256
,
json
)
|>
Base
.
encode64
())
...
...
@@ -57,8 +58,8 @@ def publish_one(%{inbox: inbox, json: json, actor: %User{} = actor, id: id} = pa
signature
=
Pleroma
.
Signature
.
sign
(
actor
,
%{
"(request-target)"
:
"post
#{
path
}
"
,
host:
host
,
"(request-target)"
:
"post
#{
uri
.
path
}
"
,
host:
signature_host
(
uri
)
,
"content-length"
:
byte_size
(
json
),
digest:
digest
,
date:
date
...
...
@@ -76,8 +77,9 @@ def publish_one(%{inbox: inbox, json: json, actor: %User{} = actor, id: id} = pa
{
"digest"
,
digest
}
]
)
do
if
!Map
.
has_key?
(
params
,
:unreachable_since
)
||
params
[
:unreachable_since
],
do
:
Instances
.
set_reachable
(
inbox
)
if
not
Map
.
has_key?
(
params
,
:unreachable_since
)
||
params
[
:unreachable_since
]
do
Instances
.
set_reachable
(
inbox
)
end
result
else
...
...
@@ -96,6 +98,14 @@ def publish_one(%{actor_id: actor_id} = params) do
|>
publish_one
()
end
defp
signature_host
(%
URI
{
port:
port
,
scheme:
scheme
,
host:
host
})
do
if
port
==
URI
.
default_port
(
scheme
)
do
host
else
"
#{
host
}
:
#{
port
}
"
end
end
defp
should_federate?
(
inbox
,
public
)
do
if
public
do
true
...
...
This diff is collapsed.
Click to expand it.
test/web/activity_pub/publisher_test.exs
+
33
−
1
View file @
1dd767b8
...
...
@@ -123,6 +123,39 @@ test "it returns inbox for messages involving single recipients in total" do
end
describe
"publish_one/1"
do
test
"publish to url with with different ports"
do
inbox80
=
"http://42.site/users/nick1/inbox"
inbox42
=
"http://42.site:42/users/nick1/inbox"
mock
(
fn
%{
method:
:post
,
url:
"http://42.site:42/users/nick1/inbox"
}
->
{
:ok
,
%
Tesla
.
Env
{
status:
200
,
body:
"port 42"
}}
%{
method:
:post
,
url:
"http://42.site/users/nick1/inbox"
}
->
{
:ok
,
%
Tesla
.
Env
{
status:
200
,
body:
"port 80"
}}
end
)
actor
=
insert
(
:user
)
assert
{
:ok
,
%{
body:
"port 42"
}}
=
Publisher
.
publish_one
(%{
inbox:
inbox42
,
json:
"{}"
,
actor:
actor
,
id:
1
,
unreachable_since:
true
})
assert
{
:ok
,
%{
body:
"port 80"
}}
=
Publisher
.
publish_one
(%{
inbox:
inbox80
,
json:
"{}"
,
actor:
actor
,
id:
1
,
unreachable_since:
true
})
end
test_with_mock
"calls `Instances.set_reachable` on successful federation if `unreachable_since` is not specified"
,
Instances
,
[
:passthrough
],
...
...
@@ -131,7 +164,6 @@ test "it returns inbox for messages involving single recipients in total" do
inbox
=
"http://200.site/users/nick1/inbox"
assert
{
:ok
,
_
}
=
Publisher
.
publish_one
(%{
inbox:
inbox
,
json:
"{}"
,
actor:
actor
,
id:
1
})
assert
called
(
Instances
.
set_reachable
(
inbox
))
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment