Skip to content

Commit

Permalink
fix unban url creation
Browse files Browse the repository at this point in the history
  • Loading branch information
umputun committed Dec 6, 2023
1 parent 1861ba4 commit 73233d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/events/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (l *TelegramListener) transformEntities(entities []tbapi.MessageEntity) *[]
func (l *TelegramListener) unbanURL(userID int64) string {
// key is SHA1 of user ID + secret
key := fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%d::%s", userID, l.AdminSecret))))
return fmt.Sprintf("%s?user=%d&token=%s", l.AdminURL, userID, key)
return fmt.Sprintf("%s/unban?user=%d&token=%s", l.AdminURL, userID, key)
}

func (l *TelegramListener) runUnbanServer(ctx context.Context) {
Expand Down
10 changes: 5 additions & 5 deletions app/events/telegram_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ func TestTelegramListener_unbanURL(t *testing.T) {
secret string
want string
}{
{"empty", "", "", "?user=123&token=d68b50c4f0747630c33bc736bb3087b4c22f19dc645ec63b3bf90760c553e1ae"},
{"test1", "http://localhost/unban", "secret",
{"empty", "", "", "/unban?user=123&token=d68b50c4f0747630c33bc736bb3087b4c22f19dc645ec63b3bf90760c553e1ae"},
{"test1", "http://localhost", "secret",
"http://localhost/unban?user=123&token=71199ea8c011a49df546451e456ad10b0016566a53c4861bf849ec6b2ad2a0b7"},
{"test2", "http://127.0.0.1:8080/unban", "secret",
{"test2", "http://127.0.0.1:8080", "secret",
"http://127.0.0.1:8080/unban?user=123&token=71199ea8c011a49df546451e456ad10b0016566a53c4861bf849ec6b2ad2a0b7"},
{"test3", "http://127.0.0.1:8080/unban", "secret2",
{"test3", "http://127.0.0.1:8080", "secret2",
"http://127.0.0.1:8080/unban?user=123&token=5385a71e8d5b65ea03e3da10175d78028ae59efd58811004e907baf422019b2e"},
}

Expand All @@ -418,7 +418,7 @@ func TestTelegramListener_unbanURL(t *testing.T) {
})
}

listener := TelegramListener{AdminURL: "http://localhost/unban", AdminSecret: "secret"}
listener := TelegramListener{AdminURL: "http://localhost", AdminSecret: "secret"}
res := listener.unbanURL(123)
assert.Equal(t, "http://localhost/unban?user=123&token=71199ea8c011a49df546451e456ad10b0016566a53c4861bf849ec6b2ad2a0b7", res)
}
Expand Down

0 comments on commit 73233d9

Please sign in to comment.