go-socks5/ruleset_test.go

48 lines
1.6 KiB
Go
Raw Permalink Normal View History

2014-01-23 19:15:53 +00:00
package socks5
import (
2020-04-19 09:08:22 +00:00
"context"
"testing"
2020-08-05 05:17:05 +00:00
2020-08-05 06:40:07 +00:00
"github.com/stretchr/testify/require"
2022-10-17 01:36:23 +00:00
"git.tcp.direct/kayos/go-socks5/statute"
)
2014-01-23 19:15:53 +00:00
func TestPermitCommand(t *testing.T) {
2020-08-05 06:40:07 +00:00
var r RuleSet
var ok bool
ctx := context.Background()
2014-01-23 19:15:53 +00:00
2020-08-05 06:40:07 +00:00
r = NewPermitAll()
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandConnect}})
2020-08-05 06:40:07 +00:00
require.True(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandBind}})
2020-08-05 06:40:07 +00:00
require.True(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandAssociate}})
2020-08-05 06:40:07 +00:00
require.True(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: 0x00}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2014-01-23 19:15:53 +00:00
2020-08-05 06:40:07 +00:00
r = NewPermitConnAndAss()
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandConnect}})
2020-08-05 06:40:07 +00:00
require.True(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandBind}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandAssociate}})
2020-08-05 06:40:07 +00:00
require.True(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: 0x00}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2014-01-23 19:15:53 +00:00
2020-08-05 06:40:07 +00:00
r = NewPermitNone()
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandConnect}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandBind}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: statute.CommandAssociate}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2020-08-05 10:10:50 +00:00
_, ok = r.Allow(ctx, &Request{Request: statute.Request{Command: 0x00}})
2020-08-05 06:40:07 +00:00
require.False(t, ok)
2014-01-23 19:15:53 +00:00
}