diff --git a/activitypub/controllers/webfinger.go b/activitypub/controllers/webfinger.go index 30a4bb6a7..26cd62c38 100644 --- a/activitypub/controllers/webfinger.go +++ b/activitypub/controllers/webfinger.go @@ -30,6 +30,7 @@ func WebfingerHandler(w http.ResponseWriter, r *http.Request) { userComponents := strings.Split(account, "@") if len(userComponents) < 2 { + w.WriteHeader(http.StatusBadRequest) return } host := userComponents[1] @@ -46,7 +47,7 @@ func WebfingerHandler(w http.ResponseWriter, r *http.Request) { // should be rejected. instanceHostString := data.GetServerURL() if instanceHostString == "" { - w.WriteHeader(http.StatusNotImplemented) + w.WriteHeader(http.StatusNotFound) return } diff --git a/test/automated/api/federation.test.js b/test/automated/api/federation.test.js index c23c368d2..89d0fa877 100644 --- a/test/automated/api/federation.test.js +++ b/test/automated/api/federation.test.js @@ -8,6 +8,9 @@ request = request('http://127.0.0.1:8080'); var ajv = new Ajv(); var nodeInfoSchema = jsonfile.readFileSync('schema/nodeinfo_2.0.json'); +const serverURL = 'owncast.server.test' +const fediUsername = 'streamer' + test('disable federation', async (done) => { const res = await sendConfigChangeRequest('federation/enable', false); done(); @@ -53,13 +56,33 @@ test('verify responses of /federation/ when federation is disabled', async (done done(); }); -test('enable federation', async (done) => { - const res = await sendConfigChangeRequest('federation/enable', true); +test('set required parameters and enable federation', async (done) => { + const res1 = await sendConfigChangeRequest( + 'serverurl', + serverURL + ); + const res2 = await sendConfigChangeRequest( + 'federation/username', + fediUsername + ); + const res3 = await sendConfigChangeRequest('federation/enable', true); done(); }); test('verify responses of /.well-known/webfinger when federation is enabled', async (done) => { - const res = request.get('/.well-known/webfinger').expect(200); + const resNoResource = request.get('/.well-known/webfinger').expect(400); + const resBadResource = request.get( + '/.well-known/webfinger?resource=' + fediUsername + '@' + serverURL + ).expect(400); + const resBadServer = request.get( + '/.well-known/webfinger?resource=acct:' + fediUsername + '@not.my.server.lol' + ).expect(404); + const resBadUser = request.get( + '/.well-known/webfinger?resource=acct:not' + fediUsername + '@' + serverURL + ).expect(404); + const res = request.get( + '/.well-known/webfinger?resource=acct:' + fediUsername + '@' + serverURL + ).expect(200); done(); });