refactor visitor IPs and allow exempting IP Ranges
Use netip.Addr instead of storing addresses as strings. This requires conversions at the database level and in tests, but is more memory efficient otherwise, and facilitates the following. Parse rate limit exemptions as netip.Prefix. This allows storing IP ranges in the exemption list. Regular IP addresses (entered explicitly or resolved from hostnames) are IPV4/32, denoting a range of one address.
This commit is contained in:
		
							parent
							
								
									e0ad926ce9
								
							
						
					
					
						commit
						c2382d29a1
					
				
					 12 changed files with 106 additions and 42 deletions
				
			
		|  | @ -3,13 +3,15 @@ package server | |||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"errors" | ||||
| 	"firebase.google.com/go/v4/messaging" | ||||
| 	"fmt" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| 	"heckel.io/ntfy/auth" | ||||
| 	"net/netip" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 	"testing" | ||||
| 
 | ||||
| 	"firebase.google.com/go/v4/messaging" | ||||
| 	"github.com/stretchr/testify/require" | ||||
| 	"heckel.io/ntfy/auth" | ||||
| ) | ||||
| 
 | ||||
| type testAuther struct { | ||||
|  | @ -322,7 +324,7 @@ func TestMaybeTruncateFCMMessage_NotTooLong(t *testing.T) { | |||
| func TestToFirebaseSender_Abuse(t *testing.T) { | ||||
| 	sender := &testFirebaseSender{allowed: 2} | ||||
| 	client := newFirebaseClient(sender, &testAuther{}) | ||||
| 	visitor := newVisitor(newTestConfig(t), newMemTestCache(t), "1.2.3.4") | ||||
| 	visitor := newVisitor(newTestConfig(t), newMemTestCache(t), netip.MustParseAddr("1.2.3.4")) | ||||
| 
 | ||||
| 	require.Nil(t, client.Send(visitor, &message{Topic: "mytopic"})) | ||||
| 	require.Equal(t, 1, len(sender.Messages())) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue