diff --git a/mockid/api/common.go b/mockid/api/common.go index 8d6b82e..b2fca1e 100644 --- a/mockid/api/common.go +++ b/mockid/api/common.go @@ -41,13 +41,18 @@ func getOpts(r *http.Request) (*options, error) { seed, _ = binary.ReadVarint(bytes.NewReader(b[0:8])) } + var n int if 0 != seed { - rndReader = rand.New(rand.NewSource(seed)) + rnd := rand.New(rand.NewSource(seed)) + rndReader = rnd + n = rnd.Intn(2) + } else { + n = rand.Intn(2) } kty, _ := tok["kty"].(string) if "" == kty { - if 0 == rand.Intn(2) { + if 0 == n { kty = "RSA" } else { kty = "EC" diff --git a/mockid/mockid_test.go b/mockid/mockid_test.go index 9e45588..db6dc69 100644 --- a/mockid/mockid_test.go +++ b/mockid/mockid_test.go @@ -121,7 +121,7 @@ func TestGenWithSeed(t *testing.T) { res, err := client.Do(&http.Request{ Method: "POST", URL: urlstr, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"test"}`))), + Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"c"}`))), }) if nil != err { //t.Fatal(err) @@ -141,7 +141,7 @@ func TestGenWithSeed(t *testing.T) { res, err = client.Do(&http.Request{ Method: "POST", URL: urlstr, - Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"test"}`))), + Body: ioutil.NopCloser(bytes.NewReader([]byte(`{"seed":"c"}`))), }) if nil != err { //t.Fatal(err)