server_vlessenc_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package service
  2. import "testing"
  3. func TestParseVlessEncAuthsAddsStableIDs(t *testing.T) {
  4. output := `
  5. Authentication: X25519, not Post-Quantum
  6. {
  7. "decryption": "mlkem768x25519plus.native.600s.server-x25519",
  8. "encryption": "mlkem768x25519plus.native.0rtt.client-x25519"
  9. }
  10. Authentication: ML-KEM-768, Post-Quantum
  11. {
  12. "decryption": "mlkem768x25519plus.native.600s.server-mlkem",
  13. "encryption": "mlkem768x25519plus.native.0rtt.client-mlkem"
  14. }
  15. `
  16. auths := parseVlessEncAuths(output)
  17. if len(auths) != 2 {
  18. t.Fatalf("expected 2 auth blocks, got %d", len(auths))
  19. }
  20. tests := []struct {
  21. index int
  22. id string
  23. label string
  24. decryption string
  25. encryption string
  26. }{
  27. {
  28. index: 0,
  29. id: "x25519",
  30. label: "X25519, not Post-Quantum",
  31. decryption: "mlkem768x25519plus.native.600s.server-x25519",
  32. encryption: "mlkem768x25519plus.native.0rtt.client-x25519",
  33. },
  34. {
  35. index: 1,
  36. id: "mlkem768",
  37. label: "ML-KEM-768, Post-Quantum",
  38. decryption: "mlkem768x25519plus.native.600s.server-mlkem",
  39. encryption: "mlkem768x25519plus.native.0rtt.client-mlkem",
  40. },
  41. }
  42. for _, test := range tests {
  43. auth := auths[test.index]
  44. if auth["id"] != test.id {
  45. t.Errorf("auth[%d] id = %q, want %q", test.index, auth["id"], test.id)
  46. }
  47. if auth["label"] != test.label {
  48. t.Errorf("auth[%d] label = %q, want %q", test.index, auth["label"], test.label)
  49. }
  50. if auth["decryption"] != test.decryption {
  51. t.Errorf("auth[%d] decryption = %q, want %q", test.index, auth["decryption"], test.decryption)
  52. }
  53. if auth["encryption"] != test.encryption {
  54. t.Errorf("auth[%d] encryption = %q, want %q", test.index, auth["encryption"], test.encryption)
  55. }
  56. }
  57. }
  58. func TestParseVlessEncAuthsHandlesMissingTrailingComma(t *testing.T) {
  59. output := `
  60. Authentication: X25519, not Post-Quantum
  61. "decryption": "server"
  62. "encryption": "client"
  63. `
  64. auths := parseVlessEncAuths(output)
  65. if len(auths) != 1 {
  66. t.Fatalf("expected 1 auth block, got %d", len(auths))
  67. }
  68. if auths[0]["decryption"] != "server" {
  69. t.Fatalf("decryption = %q, want server", auths[0]["decryption"])
  70. }
  71. if auths[0]["encryption"] != "client" {
  72. t.Fatalf("encryption = %q, want client", auths[0]["encryption"])
  73. }
  74. }