diff options
| author | Shulhan <ms@kilabit.info> | 2023-09-13 22:05:30 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-09-13 23:17:40 +0700 |
| commit | 435bb123ad81c9f38791df6c03006e6ddbcbc70d (patch) | |
| tree | ba94bec40c92ed3cf4ee3fa7eb61bf939b4fa712 /lib/http/server_test.go | |
| parent | def105e93b21c3acd8e746dde1e43f69059b02ed (diff) | |
| download | pakakeh.go-435bb123ad81c9f38791df6c03006e6ddbcbc70d.tar.xz | |
lib/ascii: replace package "math/rand" with "crypto/rand"
Since Go 1.20 the "math/rand.Seed" is considered deprecated (the initial
value of rand is seeded automatically, not zero).
Now, it is the time to replace "math/rand" with more secure random number
generator, from "crypto/rand".
This changes affect tests in package "lib/email", "lib/http", and
"lib/stmp".
Diffstat (limited to 'lib/http/server_test.go')
| -rw-r--r-- | lib/http/server_test.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/http/server_test.go b/lib/http/server_test.go index fd7330d6..7c4f2087 100644 --- a/lib/http/server_test.go +++ b/lib/http/server_test.go @@ -9,7 +9,9 @@ import ( "errors" "fmt" "io" + "mime" "net/http" + "strings" "testing" liberrors "github.com/shuLhan/share/lib/errors" @@ -934,11 +936,25 @@ func TestServer_handleRange(t *testing.T) { t.Fatal(err) } + // Replace boundary with fixed string. + var params map[string]string + + _, params, _ = mime.ParseMediaType(httpRes.Header.Get(HeaderContentType)) + + var ( + boundary = params[`boundary`] + fixedBoundary = `1b4df158039f7cce` + ) + var ( tag = `http_headers` exp = tdata.Output[tag] got = dumpHttpResponse(httpRes, skipHeaders) ) + + if len(boundary) != 0 { + got = strings.ReplaceAll(got, boundary, fixedBoundary) + } test.Assert(t, tag, string(exp), got) tag = `http_body` @@ -947,6 +963,10 @@ func TestServer_handleRange(t *testing.T) { // Replace the response body CRLF with LF. resBody = bytes.ReplaceAll(resBody, []byte("\r\n"), []byte("\n")) + if len(boundary) != 0 { + resBody = bytes.ReplaceAll(resBody, []byte(boundary), []byte(fixedBoundary)) + } + test.Assert(t, tag, string(exp), string(resBody)) tag = `all_body` |
