From ce7259ddc596f030daadb73853321c36b9a97063 Mon Sep 17 00:00:00 2001 From: Doug Lauder Date: Fri, 1 Dec 2023 11:33:13 -0500 Subject: [PATCH] fix mung of usernames on collision in shared channels; tilde is not a valid character (#25575) --- server/platform/services/sharedchannel/util.go | 4 +++- .../platform/services/sharedchannel/util_test.go | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server/platform/services/sharedchannel/util.go b/server/platform/services/sharedchannel/util.go index a1d8f7ec6d..dde1e3fddc 100644 --- a/server/platform/services/sharedchannel/util.go +++ b/server/platform/services/sharedchannel/util.go @@ -47,12 +47,14 @@ func sanitizeUserForSync(user *model.User) *model.User { return user } +const MungUsernameSeparator = "-" + // mungUsername creates a new username by combining username and remote cluster name, plus // a suffix to create uniqueness. If the resulting username exceeds the max length then // it is truncated and ellipses added. func mungUsername(username string, remotename string, suffix string, maxLen int) string { if suffix != "" { - suffix = "~" + suffix + suffix = MungUsernameSeparator + suffix } // If the username already contains a colon then another server already munged it. diff --git a/server/platform/services/sharedchannel/util_test.go b/server/platform/services/sharedchannel/util_test.go index 0c5ec5a540..c1e781912e 100644 --- a/server/platform/services/sharedchannel/util_test.go +++ b/server/platform/services/sharedchannel/util_test.go @@ -25,25 +25,25 @@ func Test_mungUsername(t *testing.T) { {"everything empty", args{username: "", remotename: "", suffix: "", maxLen: 64}, ":"}, {"no trunc, no suffix", args{username: "bart", remotename: "example.com", suffix: "", maxLen: 64}, "bart:example.com"}, - {"no trunc, suffix", args{username: "bart", remotename: "example.com", suffix: "2", maxLen: 64}, "bart~2:example.com"}, + {"no trunc, suffix", args{username: "bart", remotename: "example.com", suffix: "2", maxLen: 64}, "bart-2:example.com"}, {"trunc remote, no suffix", args{username: "bart", remotename: "example1234567890.com", suffix: "", maxLen: 24}, "bart:example123456789..."}, - {"trunc remote, suffix", args{username: "bart", remotename: "example1234567890.com", suffix: "2", maxLen: 24}, "bart~2:example1234567..."}, + {"trunc remote, suffix", args{username: "bart", remotename: "example1234567890.com", suffix: "2", maxLen: 24}, "bart-2:example1234567..."}, {"trunc both, no suffix", args{username: R(24, "A"), remotename: R(24, "B"), suffix: "", maxLen: 24}, "AAAAAAAAA...:BBBBBBBB..."}, - {"trunc both, suffix", args{username: R(24, "A"), remotename: R(24, "B"), suffix: "10", maxLen: 24}, "AAAAAA~10...:BBBBBBBB..."}, + {"trunc both, suffix", args{username: R(24, "A"), remotename: R(24, "B"), suffix: "10", maxLen: 24}, "AAAAAA-10...:BBBBBBBB..."}, {"trunc user, no suffix", args{username: R(40, "A"), remotename: "abc", suffix: "", maxLen: 24}, "AAAAAAAAAAAAAAAAA...:abc"}, - {"trunc user, suffix", args{username: R(40, "A"), remotename: "abc", suffix: "11", maxLen: 24}, "AAAAAAAAAAAAAA~11...:abc"}, + {"trunc user, suffix", args{username: R(40, "A"), remotename: "abc", suffix: "11", maxLen: 24}, "AAAAAAAAAAAAAA-11...:abc"}, {"trunc user, remote, no suffix", args{username: R(40, "A"), remotename: "abcdefghijk", suffix: "", maxLen: 24}, "AAAAAAAAA...:abcdefghijk"}, - {"trunc user, remote, suffix", args{username: R(40, "A"), remotename: "abcdefghijk", suffix: "19", maxLen: 24}, "AAAAAA~19...:abcdefghijk"}, + {"trunc user, remote, suffix", args{username: R(40, "A"), remotename: "abcdefghijk", suffix: "19", maxLen: 24}, "AAAAAA-19...:abcdefghijk"}, {"short user, long remote, no suffix", args{username: "bart", remotename: R(40, "B"), suffix: "", maxLen: 24}, "bart:BBBBBBBBBBBBBBBB..."}, {"long user, short remote, no suffix", args{username: R(40, "A"), remotename: "abc.com", suffix: "", maxLen: 24}, "AAAAAAAAAAAAA...:abc.com"}, - {"short user, long remote, suffix", args{username: "bart", remotename: R(40, "B"), suffix: "12", maxLen: 24}, "bart~12:BBBBBBBBBBBBB..."}, - {"long user, short remote, suffix", args{username: R(40, "A"), remotename: "abc.com", suffix: "12", maxLen: 24}, "AAAAAAAAAA~12...:abc.com"}, + {"short user, long remote, suffix", args{username: "bart", remotename: R(40, "B"), suffix: "12", maxLen: 24}, "bart-12:BBBBBBBBBBBBB..."}, + {"long user, short remote, suffix", args{username: R(40, "A"), remotename: "abc.com", suffix: "12", maxLen: 24}, "AAAAAAAAAA-12...:abc.com"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {