(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func TestAuthFirstPacket(t *testing.T) { |
| 129 | pvBytes, _ := hex.DecodeString("10de5a3c4a4d04efafc3e06d1506363a72bd6d053baef123e6a9a79a0c04b547") |
| 130 | p, _ := ecdh.Unmarshal(pvBytes) |
| 131 | |
| 132 | getNewState := func() *State { |
| 133 | sta, _ := InitState(RawConfig{}, common.WorldOfTime(time.Unix(1565998966, 0))) |
| 134 | sta.StaticPv = p.(crypto.PrivateKey) |
| 135 | sta.ProxyBook["shadowsocks"] = nil |
| 136 | return sta |
| 137 | } |
| 138 | |
| 139 | t.Run("TLS correct", func(t *testing.T) { |
| 140 | sta := getNewState() |
| 141 | chBytes, _ := hex.DecodeString("1603010200010001fc0303ac530b5778469dbbc3f9a83c6ac35b63aa6a70c2014026ade30f2faf0266f0242068424f320bcad49b4315a761f9f6dec32b0a403c2d8c0ab337608a694c6e411c0024130113031302c02bc02fcca9cca8c02cc030c00ac009c013c01400330039002f0035000a0100018f00000011000f00000c7777772e62696e672e636f6d00170000ff01000100000a000e000c001d00170018001901000101000b00020100002300000010000e000c02683208687474702f312e310005000501000000000033006b0069001d00204655c2c83aaed1db2e89ed17d671fcdc76dc96e36bde8840022f1bda2f31019600170041543af1f8d28b37d984073f40e8361613da502f16e4039f00656f427de0f66480b2e77e3e552e126bb0cc097168f6e5454c7f9501126a2377fb40151f6cfc007e0e002b0009080304030303020301000d0018001604030503060308040805080604010501060102030201002d00020101001c00024001001500920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") |
| 142 | info, _, err := AuthFirstPacket(chBytes, TLS{}, sta) |
| 143 | if err != nil { |
| 144 | t.Errorf("failed to get client info: %v", err) |
| 145 | return |
| 146 | } |
| 147 | if info.SessionId != 3710878841 { |
| 148 | t.Error("failed to get correct session id") |
| 149 | return |
| 150 | } |
| 151 | if info.Transport.(fmt.Stringer).String() != "TLS" { |
| 152 | t.Errorf("wrong transport: %v", info.Transport) |
| 153 | return |
| 154 | } |
| 155 | }) |
| 156 | t.Run("TLS correct but replay", func(t *testing.T) { |
| 157 | sta := getNewState() |
| 158 | chBytes, _ := hex.DecodeString("1603010200010001fc0303ac530b5778469dbbc3f9a83c6ac35b63aa6a70c2014026ade30f2faf0266f0242068424f320bcad49b4315a761f9f6dec32b0a403c2d8c0ab337608a694c6e411c0024130113031302c02bc02fcca9cca8c02cc030c00ac009c013c01400330039002f0035000a0100018f00000011000f00000c7777772e62696e672e636f6d00170000ff01000100000a000e000c001d00170018001901000101000b00020100002300000010000e000c02683208687474702f312e310005000501000000000033006b0069001d00204655c2c83aaed1db2e89ed17d671fcdc76dc96e36bde8840022f1bda2f31019600170041543af1f8d28b37d984073f40e8361613da502f16e4039f00656f427de0f66480b2e77e3e552e126bb0cc097168f6e5454c7f9501126a2377fb40151f6cfc007e0e002b0009080304030303020301000d0018001604030503060308040805080604010501060102030201002d00020101001c00024001001500920000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") |
| 159 | _, _, err := AuthFirstPacket(chBytes, TLS{}, sta) |
| 160 | if err != nil { |
| 161 | t.Error("failed to prepare for the first time") |
| 162 | return |
| 163 | } |
| 164 | _, _, err = AuthFirstPacket(chBytes, TLS{}, sta) |
| 165 | if err != ErrReplay { |
| 166 | t.Errorf("failed to return ErrReplay, got %v instead", err) |
| 167 | return |
| 168 | } |
| 169 | }) |
| 170 | t.Run("Websocket correct", func(t *testing.T) { |
| 171 | sta, _ := InitState(RawConfig{}, common.WorldOfTime(time.Unix(1584358419, 0))) |
| 172 | sta.StaticPv = p.(crypto.PrivateKey) |
| 173 | sta.ProxyBook["shadowsocks"] = nil |
| 174 | |
| 175 | req := `GET / HTTP/1.1 |
| 176 | Host: d2jkinvisak5y9.cloudfront.net:443 |
| 177 | User-Agent: Go-http-client/1.1 |
| 178 | Connection: Upgrade |
| 179 | Hidden: oJxeEwfDWg5k5Jbl8ttZD1sc0fHp8VjEtXHsqEoSrnaLRe/M+KGXkOzpc/2fRRg9Vk+wIWRsfv8IpoBPLbqO+ZfGsPXTjUJGiI9BqxrcJfkxncXA7FAHGpTc84tzBtZZ |
| 180 | Sec-WebSocket-Key: lJYh7X8DRXW1U0h9WKwVMA== |
| 181 | Sec-WebSocket-Version: 13 |
| 182 | Upgrade: websocket |
| 183 | |
| 184 | ` |
| 185 | info, _, err := AuthFirstPacket([]byte(req), WebSocket{}, sta) |
nothing calls this directly
no test coverage detected