我有一個 golang 項目的測試用例,該項目使用 crypto/tls 啟動 TLS 客戶端和服務器。我的測試訪問客戶端和服務器交換的密文以運行斷言。我正在尋找一種方法來在測試的連續執行中獲得相同的密文。協商密鑰的值和服務器返回的明文與測試無關。
1 回答

互換的青春
TA貢獻1797條經驗 獲得超6個贊
tls 示例的測試示例可以幫助您,為of定義一個zeroSource
已實現的Read
接口。Rand
tls.config
type zeroSource struct{}
func (zeroSource) Read(b []byte) (n int, err error) {
for i := range b {
b[i] = 0
}
// assign the same key to b
return len(b), nil
}
// server side
server.TLS = &tls.Config{
Rand: zeroSource{}, // for example only; don't do this.
}
// client side
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
Rand: zeroSource{}, // for reproducible output; don't do this.
},
},
}
- 1 回答
- 0 關注
- 147 瀏覽
添加回答
舉報
0/150
提交
取消