Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
gordon
funkwhale
Commits
e793f836
Verified
Commit
e793f836
authored
7 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Webfinger utils
parent
90c1d029
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/funkwhale_api/federation/webfinger.py
+52
-0
52 additions, 0 deletions
api/funkwhale_api/federation/webfinger.py
api/tests/federation/test_webfinger.py
+66
-0
66 additions, 0 deletions
api/tests/federation/test_webfinger.py
with
118 additions
and
0 deletions
api/funkwhale_api/federation/webfinger.py
0 → 100644
+
52
−
0
View file @
e793f836
from
django
import
forms
from
django.conf
import
settings
from
django.urls
import
reverse
from
.
import
utils
VALID_RESOURCE_TYPES
=
[
'
acct
'
]
def
clean_resource
(
resource_string
):
if
not
resource_string
:
raise
forms
.
ValidationError
(
'
Invalid resource string
'
)
try
:
resource_type
,
resource
=
resource_string
.
split
(
'
:
'
,
1
)
except
ValueError
:
raise
forms
.
ValidationError
(
'
Missing webfinger resource type
'
)
if
resource_type
not
in
VALID_RESOURCE_TYPES
:
raise
forms
.
ValidationError
(
'
Invalid webfinger resource type
'
)
return
resource_type
,
resource
def
clean_acct
(
acct_string
):
try
:
username
,
hostname
=
acct_string
.
split
(
'
@
'
)
except
ValueError
:
raise
forms
.
ValidationError
(
'
Invalid format
'
)
if
hostname
!=
settings
.
FEDERATION_HOSTNAME
:
raise
forms
.
ValidationError
(
'
Invalid hostname
'
)
if
username
!=
'
service
'
:
raise
forms
.
ValidationError
(
'
Invalid username
'
)
return
username
,
hostname
def
serialize_system_acct
():
return
{
'
subject
'
:
'
acct:service@{}
'
.
format
(
settings
.
FEDERATION_HOSTNAME
),
'
aliases
'
:
[
utils
.
full_url
(
reverse
(
'
federation:instance-actor
'
))
],
'
links
'
:
[
{
'
rel
'
:
'
self
'
,
'
type
'
:
'
application/activity+json
'
,
'
href
'
:
utils
.
full_url
(
reverse
(
'
federation:instance-actor
'
)),
}
]
}
This diff is collapsed.
Click to expand it.
api/tests/federation/test_webfinger.py
0 → 100644
+
66
−
0
View file @
e793f836
import
pytest
from
django
import
forms
from
django.urls
import
reverse
from
funkwhale_api.federation
import
webfinger
def
test_webfinger_clean_resource
():
t
,
r
=
webfinger
.
clean_resource
(
'
acct:service@test.federation
'
)
assert
t
==
'
acct
'
assert
r
==
'
service@test.federation
'
@pytest.mark.parametrize
(
'
resource,message
'
,
[
(
''
,
'
Invalid resource string
'
),
(
'
service@test.com
'
,
'
Missing webfinger resource type
'
),
(
'
noop:service@test.com
'
,
'
Invalid webfinger resource type
'
),
])
def
test_webfinger_clean_resource_errors
(
resource
,
message
):
with
pytest
.
raises
(
forms
.
ValidationError
)
as
excinfo
:
webfinger
.
clean_resource
(
resource
)
assert
message
==
str
(
excinfo
)
def
test_webfinger_clean_acct
(
settings
):
settings
.
FEDERATION_HOSTNAME
=
'
test.federation
'
username
,
hostname
=
webfinger
.
clean_acct
(
'
service@test.federation
'
)
assert
username
==
'
service
'
assert
hostname
==
'
test.federation
'
@pytest.mark.parametrize
(
'
resource,message
'
,
[
(
'
service
'
,
'
Invalid format
'
),
(
'
service@test.com
'
,
'
Invalid hostname
'
),
(
'
noop@test.federation
'
,
'
Invalid account
'
),
])
def
test_webfinger_clean_acct_errors
(
resource
,
message
,
settings
):
settings
.
FEDERATION_HOSTNAME
=
'
test.federation
'
with
pytest
.
raises
(
forms
.
ValidationError
)
as
excinfo
:
webfinger
.
clean_resource
(
resource
)
assert
message
==
str
(
excinfo
)
def
test_service_serializer
(
settings
):
settings
.
FEDERATION_HOSTNAME
=
'
test.federation
'
settings
.
FUNKWHALE_URL
=
'
https://test.federation
'
expected
=
{
'
subject
'
:
'
acct:service@test.federation
'
,
'
links
'
:
[
{
'
rel
'
:
'
self
'
,
'
href
'
:
'
https://test.federation/instance/actor
'
,
'
type
'
:
'
application/activity+json
'
,
}
],
'
aliases
'
:
[
'
https://test.federation/instance/actor
'
,
]
}
assert
expected
==
webfinger
.
serialize_system_acct
()
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