From f32e19f66881ed0939d83e2810c29081d5b11e16 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Sat, 19 May 2018 06:11:45 +0000 Subject: [PATCH] webfinger: add tests --- .../fixtures/httpoison_mock/kaniini@gerzilla.de.json | 1 + test/support/httpoison_mock.ex | 12 ++++++++++++ test/web/web_finger/web_finger_test.exs | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/httpoison_mock/kaniini@gerzilla.de.json diff --git a/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json b/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json new file mode 100644 index 000000000..be2f69b18 --- /dev/null +++ b/test/fixtures/httpoison_mock/kaniini@gerzilla.de.json @@ -0,0 +1 @@ +{"subject":"acct:kaniini","aliases":["https:\/\/gerzilla.de\/channel\/kaniini","https:\/\/gerzilla.de\/~kaniini","acct:kaniini@gerzilla.de"],"properties":{"http:\/\/webfinger.net\/ns\/name":"kaniini","http:\/\/xmlns.com\/foaf\/0.1\/name":"kaniini","https:\/\/w3id.org\/security\/v1#publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAvXCDkQPw+1N8B2CUd5s2\nbYvjHt+t7soMNfUiRy0qGbgW46S45k5lCq1KpbFIX3sgGZ4OWjnXVbvjCJi4kl5M\nfm5DBXzpuu05AmjVl8hqk4GejajiE\/1Nq0uWHPiOSFWispUjCzzCu65V+IsiE5JU\nvcL6WEf\/pYNRq7gYqyT693F7+cO5\/rVv9OScx5UOxbIuU1VXYhdHCqAMDJWadC89\nhePrcD3HOQKl06W2tDxHcWk6QjrdsUQGbNOgK\/QIN9gSxA+rCFEvH5O0HAhI0aXq\ncOB+vysJUFLeQOAqmAKvKS5V6RqE1GqqT0pDWHack4EmQi0gkgVzo+45xoP6wfDl\nWwG88w21LNxGvGHuN4I8mg6cEoApqKQBSOj086UtfDfSlPC1B+PRD2phE5etucHd\nF\/RIWN3SxVzU9BKIiaDm2gwOpvI8QuorQb6HDtZFO5NsSN3PnMnSywPe7kXl\/469\nuQRYXrseqyOVIi6WjhvXkyWVKVE5CBz+S8wXHfKph+9YOyUcJeAVMijp9wrjBlMc\noSzOGu79oM7tpMSq\/Xo6ePJ\/glNOwZR+OKrg92Qp9BGTKDNwGrxuxP\/9KwWtGLNf\nOMTtIkxtC3ubhxL3lBxOd7l+Bmum0UJV2f8ogkCgvTpIz05jMoyU8qWl6kkWNQlY\nDropXWaOfy7Lac+G4qlfSgsCAwEAAQ==\n-----END PUBLIC KEY-----\n","http:\/\/purl.org\/zot\/federation":"zot,activitypub"},"links":[{"rel":"http:\/\/webfinger.net\/rel\/avatar","type":"image\/png","href":"https:\/\/gerzilla.de\/photo\/profile\/l\/281"},{"rel":"http:\/\/microformats.org\/profile\/hcard","type":"text\/html","href":"https:\/\/gerzilla.de\/hcard\/kaniini"},{"rel":"http:\/\/webfinger.net\/rel\/profile-page","href":"https:\/\/gerzilla.de\/profile\/kaniini"},{"rel":"http:\/\/schemas.google.com\/g\/2010#updates-from","type":"application\/atom+xml","href":"https:\/\/gerzilla.de\/ofeed\/kaniini"},{"rel":"http:\/\/webfinger.net\/rel\/blog","href":"https:\/\/gerzilla.de\/channel\/kaniini"},{"rel":"http:\/\/ostatus.org\/schema\/1.0\/subscribe","template":"https:\/\/gerzilla.de\/follow?f=&url={uri}"},{"rel":"http:\/\/purl.org\/zot\/protocol","href":"https:\/\/gerzilla.de\/.well-known\/zot-info?address=kaniini@gerzilla.de"},{"rel":"http:\/\/purl.org\/openwebauth\/v1","type":"application\/x-zot+json","href":"https:\/\/gerzilla.de\/owa"},{"rel":"magic-public-key","href":"data:application\/magic-public-key,RSA.AL1wg5ED8PtTfAdglHebNm2L4x7fre7KDDX1IkctKhm4FuOkuOZOZQqtSqWxSF97IBmeDlo511W74wiYuJJeTH5uQwV86brtOQJo1ZfIapOBno2o4hP9TatLlhz4jkhVorKVIws8wruuVfiLIhOSVL3C-lhH_6WDUau4GKsk-vdxe_nDuf61b_TknMeVDsWyLlNVV2IXRwqgDAyVmnQvPYXj63A9xzkCpdOltrQ8R3FpOkI63bFEBmzToCv0CDfYEsQPqwhRLx-TtBwISNGl6nDgfr8rCVBS3kDgKpgCrykuVekahNRqqk9KQ1h2nJOBJkItIJIFc6PuOcaD-sHw5VsBvPMNtSzcRrxh7jeCPJoOnBKAKaikAUjo9POlLXw30pTwtQfj0Q9qYROXrbnB3Rf0SFjd0sVc1PQSiImg5toMDqbyPELqK0G-hw7WRTuTbEjdz5zJ0ssD3u5F5f-OvbkEWF67HqsjlSIulo4b15MllSlROQgc_kvMFx3yqYfvWDslHCXgFTIo6fcK4wZTHKEszhru_aDO7aTEqv16Onjyf4JTTsGUfjiq4PdkKfQRkygzcBq8bsT__SsFrRizXzjE7SJMbQt7m4cS95QcTne5fgZrptFCVdn_KIJAoL06SM9OYzKMlPKlpepJFjUJWA66KV1mjn8uy2nPhuKpX0oL.AQAB"},{"rel":"self","type":"application\/ld+json; profile=\"https:\/\/www.w3.org\/ns\/activitystreams\"","href":"https:\/\/gerzilla.de\/channel\/kaniini"}]} diff --git a/test/support/httpoison_mock.ex b/test/support/httpoison_mock.ex index 4a5a9ea85..e733afa59 100644 --- a/test/support/httpoison_mock.ex +++ b/test/support/httpoison_mock.ex @@ -3,6 +3,18 @@ defmodule HTTPoisonMock do def get(url, body \\ [], headers \\ []) + def get( + "http://gerzilla.de/.well-known/webfinger?resource=acct:kaniini@gerzilla.de", + [Accept: "application/xrd+xml,application/jrd+json"], + follow_redirect: true + ) do + {:ok, + %Response{ + status_code: 200, + body: File.read!("test/fixtures/httpoison_mock/kaniini@gerzilla.de.json") + }} + end + def get( "http://framatube.org/.well-known/webfinger?resource=acct:framasoft@framatube.org", [Accept: "application/xrd+xml,application/jrd+json"], diff --git a/test/web/web_finger/web_finger_test.exs b/test/web/web_finger/web_finger_test.exs index 69216f393..2d6ff2656 100644 --- a/test/web/web_finger/web_finger_test.exs +++ b/test/web/web_finger/web_finger_test.exs @@ -49,6 +49,14 @@ test "returns the ActivityPub actor URI for an ActivityPub user" do {:ok, _data} = WebFinger.finger(user) end + test "returns the ActivityPub actor URI for an ActivityPub user with the ld+json mimetype" do + user = "kaniini@gerzilla.de" + + {:ok, data} = WebFinger.finger(user) + + assert data["ap_id"] == "https://gerzilla.de/channel/kaniini" + end + test "returns the correctly for json ostatus users" do user = "winterdienst@gnusocial.de"