mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-02-05 07:37:02 +01:00
Add VAPID public key to instance info API
This commit is contained in:
parent
821c1da688
commit
86fcc61879
3 changed files with 28 additions and 1 deletions
|
@ -174,6 +174,8 @@ type InstanceV2Configuration struct {
|
||||||
Emojis InstanceConfigurationEmojis `json:"emojis"`
|
Emojis InstanceConfigurationEmojis `json:"emojis"`
|
||||||
// True if instance is running with OIDC as auth/identity backend, else omitted.
|
// True if instance is running with OIDC as auth/identity backend, else omitted.
|
||||||
OIDCEnabled bool `json:"oidc_enabled,omitempty"`
|
OIDCEnabled bool `json:"oidc_enabled,omitempty"`
|
||||||
|
// Instance VAPID configuration.
|
||||||
|
VAPID InstanceV2ConfigurationVAPID `json:"vapid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Information about registering for this instance.
|
// Information about registering for this instance.
|
||||||
|
@ -204,3 +206,11 @@ type InstanceV2Contact struct {
|
||||||
// Key/value not present if no contact account set.
|
// Key/value not present if no contact account set.
|
||||||
Account *Account `json:"account,omitempty"`
|
Account *Account `json:"account,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InstanceV2ConfigurationVAPID holds the instance's VAPID configuration.
|
||||||
|
//
|
||||||
|
// swagger:model instanceV2ConfigurationVAPID
|
||||||
|
type InstanceV2ConfigurationVAPID struct {
|
||||||
|
// The instance's VAPID public key, Base64-encoded.
|
||||||
|
PublicKey string `json:"public_key"`
|
||||||
|
}
|
||||||
|
|
|
@ -1878,6 +1878,12 @@ func (c *Converter) InstanceToAPIV2Instance(ctx context.Context, i *gtsmodel.Ins
|
||||||
instance.Configuration.Emojis.EmojiSizeLimit = int(config.GetMediaEmojiLocalMaxSize()) // #nosec G115 -- Already validated.
|
instance.Configuration.Emojis.EmojiSizeLimit = int(config.GetMediaEmojiLocalMaxSize()) // #nosec G115 -- Already validated.
|
||||||
instance.Configuration.OIDCEnabled = config.GetOIDCEnabled()
|
instance.Configuration.OIDCEnabled = config.GetOIDCEnabled()
|
||||||
|
|
||||||
|
vapidKeyPair, err := c.state.DB.GetVAPIDKeyPair(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, gtserror.Newf("error getting VAPID key pair: %w", err)
|
||||||
|
}
|
||||||
|
instance.Configuration.VAPID.PublicKey = vapidKeyPair.Public
|
||||||
|
|
||||||
// registrations
|
// registrations
|
||||||
instance.Registrations.Enabled = config.GetAccountsRegistrationOpen()
|
instance.Registrations.Enabled = config.GetAccountsRegistrationOpen()
|
||||||
instance.Registrations.ApprovalRequired = true // always required
|
instance.Registrations.ApprovalRequired = true // always required
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
@ -2061,6 +2062,13 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() {
|
||||||
b, err := json.MarshalIndent(instance, "", " ")
|
b, err := json.MarshalIndent(instance, "", " ")
|
||||||
suite.NoError(err)
|
suite.NoError(err)
|
||||||
|
|
||||||
|
// The VAPID public key changes from run to run.
|
||||||
|
vapidKeyPair, err := suite.db.GetVAPIDKeyPair(ctx)
|
||||||
|
if err != nil {
|
||||||
|
suite.FailNow(err.Error())
|
||||||
|
}
|
||||||
|
s := strings.Replace(string(b), vapidKeyPair.Public, "VAPID_PUBLIC_KEY_PLACEHOLDER", 1)
|
||||||
|
|
||||||
suite.Equal(`{
|
suite.Equal(`{
|
||||||
"domain": "localhost:8080",
|
"domain": "localhost:8080",
|
||||||
"account_domain": "localhost:8080",
|
"account_domain": "localhost:8080",
|
||||||
|
@ -2140,6 +2148,9 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() {
|
||||||
},
|
},
|
||||||
"emojis": {
|
"emojis": {
|
||||||
"emoji_size_limit": 51200
|
"emoji_size_limit": 51200
|
||||||
|
},
|
||||||
|
"vapid": {
|
||||||
|
"public_key": "VAPID_PUBLIC_KEY_PLACEHOLDER"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"registrations": {
|
"registrations": {
|
||||||
|
@ -2184,7 +2195,7 @@ func (suite *InternalToFrontendTestSuite) TestInstanceV2ToFrontend() {
|
||||||
"rules": [],
|
"rules": [],
|
||||||
"terms": "\u003cp\u003eThis is where a list of terms and conditions might go.\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cp\u003eIf you want to sign up on this instance, you oughta know that we:\u003c/p\u003e\u003col\u003e\u003cli\u003eWill sell your data to whoever offers.\u003c/li\u003e\u003cli\u003eSecure the server with password \u003ccode\u003epassword\u003c/code\u003e wherever possible.\u003c/li\u003e\u003c/ol\u003e",
|
"terms": "\u003cp\u003eThis is where a list of terms and conditions might go.\u003c/p\u003e\u003cp\u003eFor example:\u003c/p\u003e\u003cp\u003eIf you want to sign up on this instance, you oughta know that we:\u003c/p\u003e\u003col\u003e\u003cli\u003eWill sell your data to whoever offers.\u003c/li\u003e\u003cli\u003eSecure the server with password \u003ccode\u003epassword\u003c/code\u003e wherever possible.\u003c/li\u003e\u003c/ol\u003e",
|
||||||
"terms_text": "This is where a list of terms and conditions might go.\n\nFor example:\n\nIf you want to sign up on this instance, you oughta know that we:\n\n1. Will sell your data to whoever offers.\n2. Secure the server with password `+"`"+`password`+"`"+` wherever possible."
|
"terms_text": "This is where a list of terms and conditions might go.\n\nFor example:\n\nIf you want to sign up on this instance, you oughta know that we:\n\n1. Will sell your data to whoever offers.\n2. Secure the server with password `+"`"+`password`+"`"+` wherever possible."
|
||||||
}`, string(b))
|
}`, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *InternalToFrontendTestSuite) TestEmojiToFrontend() {
|
func (suite *InternalToFrontendTestSuite) TestEmojiToFrontend() {
|
||||||
|
|
Loading…
Reference in a new issue