You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.7 KiB

package portservice
import (
"testing"
"tera-clone/services/tera-api/internal/domain"
)
func TestOperationsShareSessionLimitAndStableIPSlots(t *testing.T) {
pool := &sessionPool{}
ssh := &service{config: serviceConfig{operation: domain.PortOperation{MaxClients: 2}}, pool: pool}
telnet := &service{config: serviceConfig{operation: domain.PortOperation{MaxClients: 2}}, pool: pool}
first, ok := beginTerminalSession(ssh, "192.168.0.100:12345")
if !ok {
t.Fatal("first SSH session rejected")
}
second, ok := beginTerminalSession(telnet, "192.168.200.100:23456")
if !ok {
t.Fatal("second Telnet session rejected")
}
if _, ok := beginTerminalSession(telnet, "192.168.200.101:34567"); ok {
t.Fatal("combined limit exceeded")
}
if slots := pool.snapshot(); slots[0] != "192.168.0.100" || slots[1] != "192.168.200.100" {
t.Fatalf("slots = %v", slots)
}
first()
first()
third, ok := beginTerminalSession(telnet, "[2001:db8::100]:45678")
if !ok {
t.Fatal("released slot not reusable")
}
if slots := pool.snapshot(); slots[0] != "2001:db8::100" || slots[1] != "192.168.200.100" {
t.Fatalf("stable slots = %v", slots)
}
third()
second()
if ssh.clients.Load() != 0 || telnet.clients.Load() != 0 {
t.Fatal("session counter leaked")
}
}
func TestOperationTwoUsesOperationOneLimitAndSeparateInterfacePort(t *testing.T) {
ports := []domain.Port{{Channel: "CH20", Operation1: domain.PortOperation{Mode: "reverse_ssh", Port: 10020, MaxClients: 2}, Operation2: domain.PortOperation{Mode: "reverse_telnet", Port: 10020, MaxClients: 4}}}
configs, err := operationConfigs(ports)
if err != nil {
t.Fatal(err)
}
if len(configs) != 2 || configs[0].operation.MaxClients != 2 || configs[1].operation.MaxClients != 2 {
t.Fatalf("configs = %+v", configs)
}
}