Skip to content

Commit

Permalink
Merge pull request #2560 from aliraza556/fix/remove-uuid-validation-h…
Browse files Browse the repository at this point in the history
…ive-author

Remove UUID validation requirement for Hive author references
  • Loading branch information
humansinstitute authored Feb 17, 2025
2 parents a45ff51 + 30817e7 commit 7b53409
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
6 changes: 0 additions & 6 deletions db/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ func validateActivity(activity *Activity) error {
}
}

if activity.Author == HiveAuthor {
if _, err := uuid.Parse(activity.AuthorRef); err != nil {
return errors.New("invalid UUID format for hive author")
}
}

return nil
}

Expand Down
8 changes: 3 additions & 5 deletions db/activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestValidateActivity(t *testing.T) {
{"Invalid ContentType", &Activity{Content: "Valid", AuthorRef: "valid_author", ContentType: "invalid_type", Author: HumansAuthor, Workspace: "valid_workspace"}, ErrInvalidContentType},
{"Invalid AuthorType", &Activity{Content: "Valid", AuthorRef: "valid_author", ContentType: FeatureCreation, Author: "invalid_author", Workspace: "valid_workspace"}, ErrInvalidAuthorType},
{"Invalid Human Author Public Key", &Activity{Content: "Valid", AuthorRef: "short_key", ContentType: FeatureCreation, Author: HumansAuthor, Workspace: "valid_workspace"}, errors.New("invalid public key format for human author")},
{"Invalid Hive Author UUID", &Activity{Content: "Valid", AuthorRef: "not-a-uuid", ContentType: FeatureCreation, Author: HiveAuthor, Workspace: "valid_workspace"}, errors.New("invalid UUID format for hive author")},
{"Valid Human Author", &Activity{Content: "Valid", AuthorRef: "abcdefghijklmnopqrstuvwxyz123456", ContentType: FeatureCreation, Author: HumansAuthor, Workspace: "valid_workspace"}, nil},
{"Valid Hive Author", &Activity{Content: "Valid", AuthorRef: uuid.NewString(), ContentType: FeatureCreation, Author: HiveAuthor, Workspace: "valid_workspace"}, nil},
}
Expand Down Expand Up @@ -108,18 +107,17 @@ func TestCreateActivity(t *testing.T) {
errorMsg: "invalid public key format for human author",
},
{
name: "Invalid activity: invalid UUID for hive author",
name: "Valid activity: hive author with URL",
setup: func() *Activity {
return &Activity{
Content: "Valid content",
ContentType: FeatureCreation,
Author: HiveAuthor,
AuthorRef: "invalid-uuid",
AuthorRef: "https://example.com/hive",
Workspace: "workspace-1",
}
},
expectError: true,
errorMsg: "invalid UUID format for hive author",
expectError: false,
},
}

Expand Down
9 changes: 0 additions & 9 deletions handlers/activity_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,15 +571,6 @@ func (ah *activityHandler) ReceiveActivity(w http.ResponseWriter, r *http.Reques
})
return
}
} else if req.Author == db.HiveAuthor {
if _, err := uuid.Parse(req.AuthorRef); err != nil {
w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(WebhookResponse{
Success: false,
Error: "invalid UUID format for hive author",
})
return
}
}

if req.ThreadID != "" {
Expand Down
16 changes: 12 additions & 4 deletions handlers/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,24 @@ func TestReceiveActivity(t *testing.T) {
expectedError: "invalid public key format for human author",
},
{
name: "invalid hive author ref",
name: "successful hive activity with URL",
payload: WebhookActivityRequest{
ContentType: "general_update",
Content: "Test content",
Workspace: "test-workspace",
Author: db.HiveAuthor,
AuthorRef: "not-a-uuid",
AuthorRef: "https://example.com/hive",
},
expectedStatus: http.StatusCreated,
validateFunc: func(t *testing.T, resp WebhookResponse) {
assert.True(t, resp.Success)
assert.NotEmpty(t, resp.ActivityID)

activity, err := db.TestDB.GetActivity(resp.ActivityID)
assert.NoError(t, err)
assert.Equal(t, "Test content", activity.Content)
assert.Equal(t, "https://example.com/hive", activity.AuthorRef)
},
expectedStatus: http.StatusBadRequest,
expectedError: "invalid UUID format for hive author",
},
{
name: "invalid thread ID format",
Expand Down

0 comments on commit 7b53409

Please sign in to comment.