1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-09-01 11:36:23 -07:00

Add is_secure_tripcode column to posts and update gochan-migration to add it

This commit is contained in:
Eggbertx 2025-04-06 15:08:46 -07:00
parent ffac903eb5
commit 4c0ce122ad
16 changed files with 182 additions and 90 deletions

View file

@ -77,44 +77,6 @@ func TestMarshalJSON(t *testing.T) {
}
}
func TestNameParsing(t *testing.T) {
testCases := []struct {
nameAndTrip string
expectedName string
expectedTripcode string
}{
{
nameAndTrip: "Name#Trip",
expectedName: "Name",
expectedTripcode: "piec1MorXg",
},
{
nameAndTrip: "#Trip",
expectedName: "",
expectedTripcode: "piec1MorXg",
},
{
nameAndTrip: "Name",
expectedName: "Name",
},
{
nameAndTrip: "Name#",
expectedName: "Name",
},
{
nameAndTrip: "#",
expectedName: "",
},
}
for _, tC := range testCases {
t.Run(tC.nameAndTrip, func(t *testing.T) {
name, trip := ParseName(tC.nameAndTrip)
assert.Equal(t, tC.expectedName, name)
assert.Equal(t, tC.expectedTripcode, trip)
})
}
}
func TestGetRealIP(t *testing.T) {
const remoteAddr = "192.168.56.1"
const testIP = "192.168.56.2"

View file

@ -17,7 +17,6 @@ import (
"strings"
"time"
"github.com/aquilax/tripcode"
"golang.org/x/crypto/bcrypt"
x_html "golang.org/x/net/html"
)
@ -147,22 +146,6 @@ func MarshalJSON(data any, indent bool) (string, error) {
return string(jsonBytes), err
}
// ParseName takes a name string from a request object and returns the name and tripcode parts
func ParseName(name string) (string, string) {
var namePart string
var tripcodePart string
if !strings.Contains(name, "#") {
namePart = name
} else if strings.Index(name, "#") == 0 {
tripcodePart = tripcode.Tripcode(name[1:])
} else if strings.Index(name, "#") > 0 {
postNameArr := strings.SplitN(name, "#", 2)
namePart = postNameArr[0]
tripcodePart = tripcode.Tripcode(postNameArr[1])
}
return namePart, tripcodePart
}
// RandomString returns a randomly generated string of the given length
func RandomString(length int) string {
var str string