From 2ff61ef8cf6b8a4226c241fd6d5df71165c9476d Mon Sep 17 00:00:00 2001 From: Ali Date: Fri, 4 Oct 2024 06:43:39 +0400 Subject: [PATCH] fixed social links for Twitter and GitHub --- cmd/chat-roulette/Dockerfile | 2 +- internal/isx/is.go | 4 ++-- internal/isx/is_test.go | 32 +++++++++++++++++++++----------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/chat-roulette/Dockerfile b/cmd/chat-roulette/Dockerfile index dc790c3..daa74aa 100644 --- a/cmd/chat-roulette/Dockerfile +++ b/cmd/chat-roulette/Dockerfile @@ -12,5 +12,5 @@ LABEL org.opencontainers.image.description="Chat Roulette for Slack" COPY --from=build /src/bin/chat-roulette /chat-roulette COPY --from=build /src/docs/examples/config.example.json /etc/config.json USER 10000:10000 -EXPOSE 8888 +EXPOSE 8080 ENTRYPOINT [ "/chat-roulette", "-c", "/etc/config.json", "--migrate" ] diff --git a/internal/isx/is.go b/internal/isx/is.go index d6f81e4..bd31e58 100644 --- a/internal/isx/is.go +++ b/internal/isx/is.go @@ -20,13 +20,13 @@ import ( var ( socialDomains = map[string]string{ "facebook": `(?:(www\.)|(m\.))?facebook.com`, - "github": "github.com", + "github": `(?:(www\.))?github.com`, "instagram": `(?:(www\.)|(m\.))?instagram.com`, "linkedin": `(?:(www\.)|(m\.)|([a-z]{2}\.))?linkedin.com`, "pinterest": `(?:(www\.))?pinterest.com`, "snapchat": `(?:(www\.))?snapchat.com`, "tiktok": `(?:(www\.)|(m\.))?tiktok.com`, - "twitter": `(?:(www\.)|(m\.))?twitter.com`, + "twitter": `(?:(www|m)\.)?(x\.com|twitter\.com)`, "youtube": `(?:(www\.)|(m\.))?youtube.com`, } ) diff --git a/internal/isx/is_test.go b/internal/isx/is_test.go index 49701ef..6d430ed 100644 --- a/internal/isx/is_test.go +++ b/internal/isx/is_test.go @@ -133,26 +133,36 @@ func Test_ProfileType(t *testing.T) { func Test_ValidateProfileLink(t *testing.T) { type test struct { + name string pType string pLink string isErr bool } tt := []test{ - {"Twitter", "twitter.com/joe", false}, - {"Instagram", "https://instagram.com/ahmed", false}, - {"LinkedIn", "facebook.com/bincyber", true}, - {"LinkedIn", "ca.linkedin.com/bincyber", false}, - {"github", "https://github.com/bincyber", false}, - {"twitter", "github.com/bincyber", true}, - {"tiktok", "tiktok.com/@example", false}, - {"pinterest", "p i n t e r e s t.com", true}, - {"snapchat", "m.snapchat.com", true}, - {"twitter", "twitter.com/", true}, + {"Twitter", "Twitter", "twitter.com/joe", false}, + {"X", "Twitter", "x.com/john", false}, + {"mobile Twitter", "Twitter", "m.twitter.com/john", false}, + {"mobile X", "Twitter", "m.x.com/john", false}, + {"missing twitter username", "Twitter", "twitter.com/", true}, + {"YouTube", "YouTube", "youtube.com/@mkbhd", false}, + {"mobile YouTube", "YouTube", "m.youtube.com/@mkbhd", false}, + {"invalid short YouTube", "YouTube", "youtu.be.com/@mkbhd", true}, + {"Insta", "Instagram", "https://instagram.com/ahmed", false}, + {"LinkedIn", "LinkedIn", "ca.linkedin.com/bincyber", false}, + {"invalid LinkedIn", "LinkedIn", "linked.in/bincyber", true}, + {"mismatch Facebook", "LinkedIn", "facebook.com/bincyber", true}, + {"github", "github", "https://github.com/bincyber", false}, + {"www github", "github", "www.github.com/bincyber", false}, + {"invalid github", "GitHub", "m.github.com/bincyber", true}, + {"mismatch GitHub", "LinkedIn", "github.com/bincyber", true}, + {"TikTok", "TikTok", "tiktok.com/@example", false}, + {"invalid pinterest", "Pinterest", "p i n t e r e s t.com", true}, + {"invalid mobile snapchat", "Snapshot", "m.snapchat.com", true}, } for _, tc := range tt { - t.Run(tc.pType, func(t *testing.T) { + t.Run(tc.name, func(t *testing.T) { err := ValidProfileLink(tc.pType, tc.pLink) if tc.isErr {