add migration & enhance int-test

This commit is contained in:
Michael Jerger 2024-05-16 18:25:16 +02:00
parent 1c7a9b00be
commit b2c3eb1644
5 changed files with 41 additions and 4 deletions

View file

@ -68,6 +68,10 @@ var migrations = []*Migration{
NewMigration("Remove Gitea-specific columns from the repository and badge tables", RemoveGiteaSpecificColumnsFromRepositoryAndBadge), NewMigration("Remove Gitea-specific columns from the repository and badge tables", RemoveGiteaSpecificColumnsFromRepositoryAndBadge),
// v15 -> v16 // v15 -> v16
NewMigration("Create the `federation_host` table", CreateFederationHostTable), NewMigration("Create the `federation_host` table", CreateFederationHostTable),
// v16 -> v17
NewMigration("Create the `federated_user` table", CreateFederatedUserTable),
// v17 -> v18
NewMigration("Add `normalized_federated_uri` column to `user` table", AddNormalizedFederatedURIToUser),
} }
// GetCurrentDBVersion returns the current Forgejo database version. // GetCurrentDBVersion returns the current Forgejo database version.

View file

@ -0,0 +1,17 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgejo_migrations //nolint:revive
import "xorm.io/xorm"
type FederatedUser struct {
ID int64 `xorm:"pk autoincr"`
UserID int64 `xorm:"NOT NULL"`
ExternalID string `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
FederationHostID int64 `xorm:"UNIQUE(federation_user_mapping) NOT NULL"`
}
func CreateFederatedUserTable(x *xorm.Engine) error {
return x.Sync(new(FederatedUser))
}

View file

@ -0,0 +1,14 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package forgejo_migrations //nolint:revive
import "xorm.io/xorm"
func AddNormalizedFederatedURIToUser(x *xorm.Engine) error {
type User struct {
ID int64 `xorm:"pk autoincr"`
NormalizedFederatedURI string
}
return x.Sync(&User{})
}

View file

@ -173,7 +173,7 @@ func CreateUserFromAP(ctx context.Context, personID fm.PersonID, federationHostI
return nil, nil, err return nil, nil, err
} }
newUser := user.User{ newUser := user.User{
LowerName: strings.ToLower(person.PreferredUsername.String()), LowerName: strings.ToLower(name),
Name: name, Name: name,
FullName: fullName, FullName: fullName,
Email: email, Email: email,

View file

@ -91,7 +91,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
`"openRegistrations":true,"usage":{"users":{"total":14,"activeHalfyear":2}},"metadata":{}}`) `"openRegistrations":true,"usage":{"users":{"total":14,"activeHalfyear":2}},"metadata":{}}`)
fmt.Fprint(res, responseBody) fmt.Fprint(res, responseBody)
}) })
federatedRoutes.HandleFunc("/api/v1/activitypub/user-id/2", federatedRoutes.HandleFunc("/api/v1/activitypub/user-id/15",
func(res http.ResponseWriter, req *http.Request) { func(res http.ResponseWriter, req *http.Request) {
// curl -H "Accept: application/json" https://federated-repo.prod.meissa.de/api/v1/activitypub/user-id/2 // curl -H "Accept: application/json" https://federated-repo.prod.meissa.de/api/v1/activitypub/user-id/2
responseBody := fmt.Sprintf(`{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],` + responseBody := fmt.Sprintf(`{"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1"],` +
@ -132,7 +132,7 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
activity := []byte(fmt.Sprintf( activity := []byte(fmt.Sprintf(
`{"type":"Like",`+ `{"type":"Like",`+
`"startTime":"%s",`+ `"startTime":"%s",`+
`"actor":"%s/api/v1/activitypub/user-id/2",`+ `"actor":"%s/api/v1/activitypub/user-id/15",`+
`"object":"%s/api/v1/activitypub/repository-id/%v"}`, `"object":"%s/api/v1/activitypub/repository-id/%v"}`,
time.Now().UTC().Format(time.RFC3339), time.Now().UTC().Format(time.RFC3339),
federatedSrv.URL, srv.URL, repositoryID)) federatedSrv.URL, srv.URL, repositoryID))
@ -142,7 +142,9 @@ func TestActivityPubRepositoryInboxValid(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, http.StatusNoContent, resp.StatusCode) assert.Equal(t, http.StatusNoContent, resp.StatusCode)
unittest.AssertExistsAndLoadBean(t, &forgefed.FederationHost{HostFqdn: "127.0.0.1"}) federationHost := unittest.AssertExistsAndLoadBean(t, &forgefed.FederationHost{HostFqdn: "127.0.0.1"})
federatedUser := unittest.AssertExistsAndLoadBean(t, &user.FederatedUser{ExternalID: "15", FederationHostID: federationHost.ID})
unittest.AssertExistsAndLoadBean(t, &user.User{ID: federatedUser.UserID})
}) })
} }