This commit is contained in:
2025-08-05 14:09:15 -04:00
parent b7b7dc7353
commit fff61ceca1
10 changed files with 39 additions and 39 deletions

View File

@@ -52,7 +52,7 @@ func TestBech32(t *testing.T) {
{
"split1cheo2y9e2w",
ErrNonCharsetChar('o'),
}, // invalid character (o) in data part
}, // invalid character (o) in data part
{"split1a2y9w", ErrInvalidSeparatorIndex(5)}, // too short data part
{
"1checkupstagehandshakeupstreamerranterredcaperred2y9e3w",

View File

@@ -87,9 +87,9 @@ type nonceAggValidCase struct {
}
type nonceAggInvalidCase struct {
Indices []int `json:"pnonce_indices"`
Error nonceAggError `json:"error"`
Comment string `json:"comment"`
Indices []int `json:"pnonce_indices"`
Error nonceAggError `json:"error"`
Comment string `json:"comment"`
ExpectedErr string `json:"btcec_err"`
}

View File

@@ -62,8 +62,8 @@ func assertDecryptFail(
) {
var (
k1, ciphertextBytes []byte
ok bool
err error
ok bool
err error
)
k1, err = hex.Dec(conversationKey)
if ok = assert.NoErrorf(

View File

@@ -84,7 +84,7 @@ func testUint16Sorting(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint16 values don't sort correctly: %v should be less than %v",
t.Errorf("Uint16 values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -115,7 +115,7 @@ func testUint24Sorting(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint24 values don't sort correctly: %v should be less than %v",
t.Errorf("Uint24 values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -143,7 +143,7 @@ func testUint32Sorting(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint32 values don't sort correctly: %v should be less than %v",
t.Errorf("Uint32 values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -174,7 +174,7 @@ func testUint40Sorting(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint40 values don't sort correctly: %v should be less than %v",
t.Errorf("Uint40 values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -202,7 +202,7 @@ func testUint64Sorting(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint64 values don't sort correctly: %v should be less than %v",
t.Errorf("Uint64 values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -233,7 +233,7 @@ func testUint16EdgeCases(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint16 edge case values don't sort correctly: %v should be less than %v",
t.Errorf("Uint16 edge case values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -265,7 +265,7 @@ func testUint24EdgeCases(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint24 edge case values don't sort correctly: %v should be less than %v",
t.Errorf("Uint24 edge case values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -294,7 +294,7 @@ func testUint32EdgeCases(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint32 edge case values don't sort correctly: %v should be less than %v",
t.Errorf("Uint32 edge case values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -326,7 +326,7 @@ func testUint40EdgeCases(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint40 edge case values don't sort correctly: %v should be less than %v",
t.Errorf("Uint40 edge case values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -355,7 +355,7 @@ func testUint64EdgeCases(t *testing.T) {
// Check if they sort correctly with bytes.Compare
for i := 0; i < len(marshaledValues)-1; i++ {
if bytes.Compare(marshaledValues[i], marshaledValues[i+1]) >= 0 {
t.Errorf("Uint64 edge case values don't sort correctly: %v should be less than %v",
t.Errorf("Uint64 edge case values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", marshaledValues[i], marshaledValues[i+1])
}
@@ -390,7 +390,7 @@ func TestEndianness(t *testing.T) {
result := bytes.Compare(bigEndianValues[i], bigEndianValues[i+1])
t.Logf("Compare %d with %d: result = %d", values[i], values[i+1], result)
if result >= 0 {
t.Errorf("BigEndian values don't sort correctly: %v should be less than %v",
t.Errorf("BigEndian values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", bigEndianValues[i], bigEndianValues[i+1])
}
@@ -404,7 +404,7 @@ func TestEndianness(t *testing.T) {
t.Logf("Compare %d with %d: result = %d", values[i], values[i+1], result)
if result >= 0 {
correctOrder = false
t.Logf("LittleEndian values don't sort correctly: %v should be less than %v",
t.Logf("LittleEndian values don't sort correctly: %v should be less than %v",
values[i], values[i+1])
t.Logf("Bytes representation: %v vs %v", littleEndianValues[i], littleEndianValues[i+1])
}

View File

@@ -112,7 +112,7 @@ func (x *Operations) RegisterEvent(api huma.API) {
err = huma.Error403Forbidden(fmt.Sprintf("Too many failed authentication attempts. Blocked until %s", blockedUntil.Format(time.RFC3339)))
return
}
authed, pubkey, super = x.UserAuth(r, remote)
if !authed {
// Record the failed authentication attempt

View File

@@ -118,7 +118,7 @@ func (p *Publisher) Receive(msg typer.T) {
Receiver: m.Receiver,
Pubkey: m.Pubkey,
}
// Add the filters if provided
if m.FilterMap != nil {
for id, f := range m.FilterMap {
@@ -126,7 +126,7 @@ func (p *Publisher) Receive(msg typer.T) {
log.T.F("added subscription %s for new listener %s", id, m.Id)
}
}
// Add the listener to the map
p.ListenMap[m.Id] = listener
log.T.F("added new listener %s", m.Id)
@@ -254,7 +254,7 @@ func CheckListenerExists(clientId string, publishers ...publisher.I) bool {
return true
}
}
// Check if the publisher has a Publishers field of type publisher.Publishers
// This handles the case where the publisher is a *publish.S
val := reflect.ValueOf(p)
@@ -290,7 +290,7 @@ func CheckSubscriptionExists(clientId string, subscriptionId string, publishers
return true
}
}
// Check if the publisher has a Publishers field of type publisher.Publishers
// This handles the case where the publisher is a *publish.S
val := reflect.ValueOf(p)

View File

@@ -72,7 +72,7 @@ func (a *A) HandleAuth(b []byte, srv server.I) (msg []byte) {
env.Event.Pubkey,
)
a.Listener.SetAuthedPubkey(env.Event.Pubkey)
// If authentication is successful, remove any blocks for this IP
iptracker.Global.Authenticate(a.Listener.RealRemote())
}

View File

@@ -75,43 +75,43 @@ func (a *A) HandleEvent(
if a.I.AuthRequired() && !a.Listener.IsAuthed() {
remoteIP := a.Listener.RealRemote()
log.I.F("requesting auth from client from %s", remoteIP)
// Check if the IP is blocked due to too many failed auth attempts
if iptracker.Global.IsBlocked(remoteIP) {
blockedUntil := iptracker.Global.GetBlockedUntil(remoteIP)
blockMsg := fmt.Sprintf("Too many failed authentication attempts. Blocked until %s",
blockMsg := fmt.Sprintf("Too many failed authentication attempts. Blocked until %s",
blockedUntil.Format(time.RFC3339))
// Send a notice to the client explaining why they're blocked
if err = noticeenvelope.NewFrom(blockMsg).Write(a.Listener); chk.E(err) {
err = nil
}
// Close the connection
log.I.F("closing connection from %s due to too many failed auth attempts", remoteIP)
a.Listener.Close()
return
}
// Record the failed authentication attempt
blocked := iptracker.Global.RecordFailedAttempt(remoteIP)
if blocked {
// If this attempt caused the IP to be blocked, close the connection
blockedUntil := iptracker.Global.GetBlockedUntil(remoteIP)
blockMsg := fmt.Sprintf("Too many failed authentication attempts. Blocked until %s",
blockMsg := fmt.Sprintf("Too many failed authentication attempts. Blocked until %s",
blockedUntil.Format(time.RFC3339))
// Send a notice to the client explaining why they're blocked
if err = noticeenvelope.NewFrom(blockMsg).Write(a.Listener); chk.E(err) {
err = nil
}
// Close the connection
log.I.F("closing connection from %s due to too many failed auth attempts", remoteIP)
a.Listener.Close()
return
}
// Continue with normal auth flow for non-blocked IPs
a.Listener.RequestAuth()
if err = Ok.AuthRequired(a, env.E, "auth required"); chk.E(err) {

View File

@@ -57,18 +57,18 @@ type A struct {
func (a *A) Serve(w http.ResponseWriter, r *http.Request, s server.I) {
c := a.Config()
remote := helpers.GetRemoteFromReq(r)
// Check if the IP is blocked due to too many failed auth attempts
if iptracker.Global.IsBlocked(remote) {
blockedUntil := iptracker.Global.GetBlockedUntil(remote)
log.I.F("rejecting websocket connection from banned IP %s (blocked until %s)",
log.I.F("rejecting websocket connection from banned IP %s (blocked until %s)",
remote, blockedUntil.Format(time.RFC3339))
// We can't send a notice to the client here because the websocket connection
// We can't send a notice to the client here because the websocket connection
// hasn't been established yet, so we just reject the connection
return
}
var whitelisted bool
if len(c.Whitelist) > 0 {
for _, addr := range c.Whitelist {

View File

@@ -108,7 +108,7 @@ func TestBytesConcurrentAccess(t *testing.T) {
loaded := atom.Load()
// Verify the loaded data is valid (either our data or another goroutine's data)
require.LessOrEqual(t, len(loaded), parallelism,
require.LessOrEqual(t, len(loaded), parallelism,
"Loaded data length should not exceed parallelism")
// If it's our data, verify it's correct