ppp_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package cli
  2. import (
  3. "strings"
  4. "testing"
  5. "debtik/internal/auth"
  6. "debtik/internal/vpn"
  7. )
  8. func TestPPPCLICommands(t *testing.T) {
  9. vpnMgr := vpn.NewManager()
  10. adminUser := &auth.PublicUser{Username: "admin", Role: auth.RoleFull}
  11. executor := &Executor{vpnMgr: vpnMgr}
  12. // 1. /ppp profile add
  13. 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)
  14. if !strings.Contains(out, "created successfully") {
  15. t.Fatalf("unexpected profile add output: %s", out)
  16. }
  17. // 2. /ppp profile print
  18. out, _ = executor.Execute("/ppp profile print", adminUser)
  19. if !strings.Contains(out, "test-p2p") || !strings.Contains(out, "192.168.133.1") {
  20. t.Fatalf("unexpected profile print output: %s", out)
  21. }
  22. // 3. /ppp profile set
  23. out, _ = executor.Execute("/ppp profile set test-p2p remote-address=192.168.133.50", adminUser)
  24. if !strings.Contains(out, "updated successfully") {
  25. t.Fatalf("unexpected profile set output: %s", out)
  26. }
  27. // 4. /ppp secret add
  28. out, _ = executor.Execute("/ppp secret add name=test-user password=secretpass profile=test-p2p remote-address=192.168.133.55", adminUser)
  29. if !strings.Contains(out, "created successfully") {
  30. t.Fatalf("unexpected secret add output: %s", out)
  31. }
  32. // 5. /ppp secret print
  33. out, _ = executor.Execute("/ppp secret print", adminUser)
  34. if !strings.Contains(out, "test-user") || !strings.Contains(out, "192.168.133.55") {
  35. t.Fatalf("unexpected secret print output: %s", out)
  36. }
  37. // 6. /ppp secret disable & enable
  38. out, _ = executor.Execute("/ppp secret disable test-user", adminUser)
  39. if !strings.Contains(out, "disabled") {
  40. t.Fatalf("unexpected secret disable output: %s", out)
  41. }
  42. out, _ = executor.Execute("/ppp secret enable test-user", adminUser)
  43. if !strings.Contains(out, "enabled") {
  44. t.Fatalf("unexpected secret enable output: %s", out)
  45. }
  46. // 7. /interface l2tp-server server print and set
  47. out, _ = executor.Execute("/interface l2tp-server server print", adminUser)
  48. if !strings.Contains(out, "ENABLED") || !strings.Contains(out, "PORT") {
  49. t.Fatalf("unexpected l2tp server print: %s", out)
  50. }
  51. out, _ = executor.Execute("/interface l2tp-server server set enabled=yes default-profile=test-p2p", adminUser)
  52. if !strings.Contains(out, "updated successfully") {
  53. t.Fatalf("unexpected l2tp server set: %s", out)
  54. }
  55. // 8. /ppp active print
  56. out, _ = executor.Execute("/ppp active print", adminUser)
  57. if !strings.Contains(out, "INTERFACE") {
  58. t.Fatalf("unexpected active print output: %s", out)
  59. }
  60. }