| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package cli
- import (
- "strings"
- "testing"
- "debtik/internal/auth"
- "debtik/internal/vpn"
- )
- func TestPPPCLICommands(t *testing.T) {
- vpnMgr := vpn.NewManager()
- adminUser := &auth.PublicUser{Username: "admin", Role: auth.RoleFull}
- executor := &Executor{vpnMgr: vpnMgr}
- // 1. /ppp profile add
- out, _ := executor.Execute("/ppp profile add name=test-p2p local-address=192.168.133.1 remote-address=192.168.133.2-192.168.133.254", adminUser)
- if !strings.Contains(out, "created successfully") {
- t.Fatalf("unexpected profile add output: %s", out)
- }
- // 2. /ppp profile print
- out, _ = executor.Execute("/ppp profile print", adminUser)
- if !strings.Contains(out, "test-p2p") || !strings.Contains(out, "192.168.133.1") {
- t.Fatalf("unexpected profile print output: %s", out)
- }
- // 3. /ppp profile set
- out, _ = executor.Execute("/ppp profile set test-p2p remote-address=192.168.133.50", adminUser)
- if !strings.Contains(out, "updated successfully") {
- t.Fatalf("unexpected profile set output: %s", out)
- }
- // 4. /ppp secret add
- out, _ = executor.Execute("/ppp secret add name=test-user password=secretpass profile=test-p2p remote-address=192.168.133.55", adminUser)
- if !strings.Contains(out, "created successfully") {
- t.Fatalf("unexpected secret add output: %s", out)
- }
- // 5. /ppp secret print
- out, _ = executor.Execute("/ppp secret print", adminUser)
- if !strings.Contains(out, "test-user") || !strings.Contains(out, "192.168.133.55") {
- t.Fatalf("unexpected secret print output: %s", out)
- }
- // 6. /ppp secret disable & enable
- out, _ = executor.Execute("/ppp secret disable test-user", adminUser)
- if !strings.Contains(out, "disabled") {
- t.Fatalf("unexpected secret disable output: %s", out)
- }
- out, _ = executor.Execute("/ppp secret enable test-user", adminUser)
- if !strings.Contains(out, "enabled") {
- t.Fatalf("unexpected secret enable output: %s", out)
- }
- // 7. /interface l2tp-server server print and set
- out, _ = executor.Execute("/interface l2tp-server server print", adminUser)
- if !strings.Contains(out, "ENABLED") || !strings.Contains(out, "PORT") {
- t.Fatalf("unexpected l2tp server print: %s", out)
- }
- out, _ = executor.Execute("/interface l2tp-server server set enabled=yes default-profile=test-p2p", adminUser)
- if !strings.Contains(out, "updated successfully") {
- t.Fatalf("unexpected l2tp server set: %s", out)
- }
- // 8. /ppp active print
- out, _ = executor.Execute("/ppp active print", adminUser)
- if !strings.Contains(out, "INTERFACE") {
- t.Fatalf("unexpected active print output: %s", out)
- }
- }
|