1
0

server_vlessenc_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. }
  75. func TestDeriveVlessEncModes(t *testing.T) {
  76. base := []map[string]string{
  77. {
  78. "id": "x25519",
  79. "label": "X25519, not Post-Quantum",
  80. "decryption": "mlkem768x25519plus.native.600s.server-key",
  81. "encryption": "mlkem768x25519plus.native.0rtt.client-key",
  82. },
  83. }
  84. derived := deriveVlessEncModes(base)
  85. if len(derived) != 2 {
  86. t.Fatalf("expected 2 derived blocks, got %d", len(derived))
  87. }
  88. if derived[0]["id"] != "x25519_xorpub" {
  89. t.Errorf("id = %q, want x25519_xorpub", derived[0]["id"])
  90. }
  91. if derived[0]["decryption"] != "mlkem768x25519plus.xorpub.600s.server-key" {
  92. t.Errorf("decryption = %q", derived[0]["decryption"])
  93. }
  94. if derived[0]["encryption"] != "mlkem768x25519plus.xorpub.0rtt.client-key" {
  95. t.Errorf("encryption = %q", derived[0]["encryption"])
  96. }
  97. if derived[1]["id"] != "x25519_random" {
  98. t.Errorf("id = %q, want x25519_random", derived[1]["id"])
  99. }
  100. }