forked from things-go/go-socks5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ruleset_test.go
47 lines (39 loc) · 1.56 KB
/
ruleset_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package socks5
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/things-go/go-socks5/statute"
)
func TestPermitCommand(t *testing.T) {
var r RuleSet
var ok bool
ctx := context.Background()
r = NewPermitAll()
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandConnect}})
require.True(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandBind}})
require.True(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandAssociate}})
require.True(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: 0x00}})
require.False(t, ok)
r = NewPermitConnAndAss()
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandConnect}})
require.True(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandBind}})
require.False(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandAssociate}})
require.True(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: 0x00}})
require.False(t, ok)
r = NewPermitNone()
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandConnect}})
require.False(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandBind}})
require.False(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandAssociate}})
require.False(t, ok)
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: 0x00}})
require.False(t, ok)
}