-
Notifications
You must be signed in to change notification settings - Fork 26
/
activityPub_test.go
63 lines (45 loc) · 1.45 KB
/
activityPub_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"crypto/x509"
"encoding/pem"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_loadActivityPubPrivateKey(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
err := app.initConfig(false)
require.NoError(t, err)
require.NotNil(t, app.db)
// Generate
err = app.loadActivityPubPrivateKey()
require.NoError(t, err)
assert.NotNil(t, app.apPrivateKey)
assert.NotEmpty(t, app.apPubKeyBytes)
oldEncodedKey := x509.MarshalPKCS1PrivateKey(app.apPrivateKey)
oldPemEncoded := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: oldEncodedKey})
// Reset and reload
err = app.loadActivityPubPrivateKey()
require.NoError(t, err)
assert.NotNil(t, app.apPrivateKey)
assert.NotEmpty(t, app.apPubKeyBytes)
newEncodedKey := x509.MarshalPKCS1PrivateKey(app.apPrivateKey)
newPemEncoded := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: newEncodedKey})
assert.Equal(t, string(oldPemEncoded), string(newPemEncoded))
}
func Test_webfinger(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
app.cfg.Server.PublicAddress = "https://example.com"
_ = app.initConfig(false)
app.prepareWebfinger()
req := httptest.NewRequest(http.MethodGet, "/.well-known/webfinger?resource=acct:[email protected]", nil)
rec := httptest.NewRecorder()
app.apHandleWebfinger(rec, req)
assert.Equal(t, http.StatusOK, rec.Code)
}