Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

fix(plugins): generate missing registered user names (#5112)

Gabe Kangasf95f20cb9115
diff --git a/pluginhost/pluginhost.go b/pluginhost/pluginhost.go
index d229137e1f..3cdf90f2a0 100644
--- a/pluginhost/pluginhost.go
+++ b/pluginhost/pluginhost.go
@@ -1936,6 +1936,13 @@ func validateProfileURL(profileURL string) error {
return nil
}
+func generatedDisplayName(displayName string) string {
+ if displayName == "" {
+ return utils.GeneratePhrase()
+ }
+ return displayName
+}
+
// wireAuthHostFns wires the viewer-authentication host functions: register an
// authenticated user for an external (plugin-provided) identity, and mint a
// signed gate session for them.
@@ -1966,7 +1973,7 @@ func wireAuthHostFns(env *plugins.HostEnv, deps Deps) {
if existing := users.GetUserByPluginAuth(pluginName, req.AuthID); existing != nil {
userID = existing.ID
} else {
- user, _, err := users.CreateAnonymousUser(req.DisplayName)
+ user, _, err := users.CreateAnonymousUser(generatedDisplayName(req.DisplayName))
if err != nil {
return "", err
}
diff --git a/pluginhost/register_test.go b/pluginhost/register_test.go
index 4261939c55..93115bd837 100644
--- a/pluginhost/register_test.go
+++ b/pluginhost/register_test.go
@@ -1,6 +1,7 @@
package pluginhost
import (
+ "encoding/json"
"testing"
"github.com/owncast/owncast/models"
@@ -82,9 +83,13 @@ func TestRegisterUser(t *testing.T) {
t.Fatalf("re-register: got %q err=%v, want %q", again, err, id)
}
- // A different plugin with the same raw authId is a distinct user. (A new-user
- // registration must carry a display name; CreateAnonymousUser rejects empty.)
- other, err := env.RegisterUser("discord-auth", plugins.UserRegisterRequest{AuthID: "583231", DisplayName: "octocat"})
+ // A different plugin with the same raw authId creates a distinct user. A
+ // nullable display name receives a generated name.
+ var nullDisplayName plugins.UserRegisterRequest
+ if err := json.Unmarshal([]byte(`{"authId":"583231","displayName":null}`), &nullDisplayName); err != nil {
+ t.Fatalf("decode nullable display name: %v", err)
+ }
+ other, err := env.RegisterUser("discord-auth", nullDisplayName)
if err != nil {
t.Fatalf("other plugin register: %v", err)
}
@@ -92,6 +97,10 @@ func TestRegisterUser(t *testing.T) {
t.Error("a different plugin must not resolve to the same user")
}
+ if user := users.GetUserByPluginAuth("discord-auth", "583231"); user == nil || user.DisplayName == "" {
+ t.Error("missing display name was not generated")
+ }
+
// A disallowed scope is rejected, and no orphan user is left behind.
if _, err := env.RegisterUser("github-auth", plugins.UserRegisterRequest{
AuthID: "scope-reject", Scopes: []string{models.ScopeHasAdminAccess},