Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Federation Library
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
6
Issues
6
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ganggo
Federation Library
Commits
59eaaf5c
Unverified
Commit
59eaaf5c
authored
Apr 05, 2018
by
zauberstuhl
Committed by
GitHub
Apr 05, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #18 from ganggo/fix_pubkey_friendica
Fix public key retrieval from friendica via hcard
parents
e0406596
8cd7111c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
37 deletions
+38
-37
hcard.go
hcard.go
+4
-0
hcard_test.go
hcard_test.go
+34
-35
helper_test.go
helper_test.go
+0
-2
No files found.
hcard.go
View file @
59eaaf5c
...
...
@@ -71,6 +71,10 @@ func (h *Hcard) Fetch(endpoint string) error {
func
(
i
int
,
s
*
goquery
.
Selection
)
{
(
*
h
)
.
PublicKey
=
s
.
Find
(
"pre"
)
.
Text
()
})
doc
.
Find
(
".key.u-key"
)
.
Each
(
func
(
i
int
,
s
*
goquery
.
Selection
)
{
(
*
h
)
.
PublicKey
=
s
.
Text
()
})
doc
.
Find
(
".entity_url"
)
.
Each
(
func
(
i
int
,
s
*
goquery
.
Selection
)
{
(
*
h
)
.
Url
=
s
.
Find
(
"a"
)
.
Text
()
...
...
hcard_test.go
View file @
59eaaf5c
...
...
@@ -23,45 +23,44 @@ import (
)
func
TestHcard
(
t
*
testing
.
T
)
{
var
hcard
Hcard
err
:=
hcard
.
Fetch
(
TEST_HCARD_LINK
)
if
err
!=
nil
{
t
.
Errorf
(
"Some error occured while parsing: %v"
,
err
)
// XXX testing on live systems could break stuff
// First link is a diaspora production server
// Second link is a diaspora development server
// Third link is a friendica production server
links
:=
[]
string
{
"https://joindiaspora.com/hcard/users/db3d5a70c1ee01334cdd5215e5076e52"
,
"https://sechat.org/hcard/users/18ad211f33c65726"
,
"https://pirati.ca/hcard/heluecht"
,
}
matched
,
err
:=
regexp
.
MatchString
(
`^[\w\d]+?$`
,
hcard
.
Guid
)
if
err
!=
nil
||
!
matched
{
t
.
Errorf
(
"Expected nil and match, got %v and %v"
,
err
,
matched
)
}
nickname
:=
"podmin"
if
hcard
.
Nickname
!=
nickname
{
t
.
Errorf
(
"Expected to be %s, got %s"
,
nickname
,
hcard
.
Nickname
)
}
matched
,
err
=
regexp
.
MatchString
(
`^-----BEGIN.+?KEY-----`
,
hcard
.
PublicKey
)
if
err
!=
nil
||
!
matched
{
t
.
Errorf
(
"Expected nil and match, got %v and '%s'"
,
err
,
hcard
.
PublicKey
)
}
url
:=
"https://joindiaspora.com/"
if
hcard
.
Url
!=
url
{
t
.
Errorf
(
"Expected to be %s, got %s"
,
url
,
hcard
.
Url
)
}
photo
:=
url
+
"uploads/images/thumb_"
matched
,
err
=
regexp
.
MatchString
(
photo
+
`large_[\w\d]+?\.png`
,
hcard
.
Photo
)
if
err
!=
nil
||
!
matched
{
t
.
Errorf
(
"Expected nil and match, got %v and %s"
,
err
,
hcard
.
Photo
)
for
_
,
link
:=
range
links
{
var
hcard
Hcard
err
:=
hcard
.
Fetch
(
link
)
if
err
!=
nil
{
t
.
Errorf
(
"Some error occured while parsing: %v"
,
err
)
}
evaluateHcard
(
hcard
,
t
)
}
}
matched
,
err
=
regexp
.
MatchString
(
photo
+
`medium_[\w\d]+?\.png`
,
hcard
.
PhotoMedium
)
if
err
!=
nil
||
!
matched
{
t
.
Errorf
(
"Expected nil and match, got %v and %s"
,
err
,
hcard
.
PhotoMedium
)
func
evaluateHcard
(
hcard
Hcard
,
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
Expected
string
Text
string
}{
{
`^[\w\d]+?$`
,
hcard
.
Guid
},
{
`^[\w\d]+?$`
,
hcard
.
Nickname
},
{
`^-----BEGIN.+?KEY-----`
,
hcard
.
PublicKey
},
{
`^[\w\d\.\:\/]+?$`
,
hcard
.
Url
},
{
`^http.*\.\w+\?{0,1}.*$`
,
hcard
.
Photo
},
{
`^http.*\.\w+\?{0,1}.*$`
,
hcard
.
PhotoSmall
},
{
`^http.*\.\w+\?{0,1}.*$`
,
hcard
.
PhotoMedium
},
}
matched
,
err
=
regexp
.
MatchString
(
photo
+
`small_[\w\d]+?\.png`
,
hcard
.
PhotoSmall
)
if
err
!=
nil
||
!
matched
{
t
.
Errorf
(
"Expected nil and match, got %v and %s"
,
err
,
hcard
.
PhotoSmall
)
for
i
,
test
:=
range
tests
{
matched
,
err
:=
regexp
.
MatchString
(
test
.
Expected
,
test
.
Text
)
if
err
!=
nil
||
!
matched
{
t
.
Errorf
(
"#%d: Expected to be '%s', got '%s' (%v)"
,
i
,
test
.
Expected
,
test
.
Text
,
err
)
}
}
}
helper_test.go
View file @
59eaaf5c
...
...
@@ -25,8 +25,6 @@ import (
var
TEST_AUTHOR
=
`diaspora_2nd@localhost:3001`
var
TEST_HCARD_LINK
=
"https://joindiaspora.com/hcard/users/db3d5a70c1ee01334cdd5215e5076e52"
var
TEST_PRIV_KEY
=
[]
byte
(
`-----BEGIN PRIVATE KEY-----
MIIEpAIBAAKCAQEA5qryP/x8Wtht+VLH/TvLNofTF9B4aj78sYlctQxIuzEmuLc3
nU+EhpeExe9DpJEt6/l5V3NIHymkkNMA7Mu4fWmxdyVMEweY7utTl+wkwdJFFlBV
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment