mirror of
https://github.com/portainer/portainer.git
synced 2026-08-07 09:04:48 +00:00
fix(deps): replace dchest/uniuri with librand.String BE-13306 (#3377)
This commit is contained in:
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/portainer/portainer/pkg/libcrypto"
|
"github.com/portainer/portainer/pkg/libcrypto"
|
||||||
"github.com/portainer/portainer/pkg/librand"
|
"github.com/portainer/portainer/pkg/librand"
|
||||||
|
|
||||||
"github.com/dchest/uniuri"
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -223,8 +222,8 @@ func randomInt(min, max int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomCredentials() (string, string) {
|
func generateRandomCredentials() (string, string) {
|
||||||
username := uniuri.NewLen(8)
|
username := librand.String(8)
|
||||||
password := uniuri.NewLen(8)
|
password := librand.String(8)
|
||||||
|
|
||||||
return username, password
|
return username, password
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
portainer "github.com/portainer/portainer/api"
|
portainer "github.com/portainer/portainer/api"
|
||||||
"github.com/portainer/portainer/api/chisel"
|
"github.com/portainer/portainer/api/chisel"
|
||||||
"github.com/portainer/portainer/api/crypto"
|
"github.com/portainer/portainer/api/crypto"
|
||||||
|
"github.com/portainer/portainer/pkg/librand"
|
||||||
|
|
||||||
"github.com/dchest/uniuri"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@@ -176,7 +176,7 @@ func (store *Store) testSSLSettings(t *testing.T) {
|
|||||||
|
|
||||||
func (store *Store) testTunnelServer(t *testing.T) {
|
func (store *Store) testTunnelServer(t *testing.T) {
|
||||||
is := assert.New(t)
|
is := assert.New(t)
|
||||||
expectPrivateKeySeed := uniuri.NewLen(16)
|
expectPrivateKeySeed := librand.String(16)
|
||||||
|
|
||||||
err := store.TunnelServer().UpdateInfo(&portainer.TunnelServerInfo{PrivateKeySeed: expectPrivateKeySeed})
|
err := store.TunnelServer().UpdateInfo(&portainer.TunnelServerInfo{PrivateKeySeed: expectPrivateKeySeed})
|
||||||
require.NoError(t, err, "UpdateInfo should have succeeded")
|
require.NoError(t, err, "UpdateInfo should have succeeded")
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ require (
|
|||||||
github.com/compose-spec/compose-go/v2 v2.9.1
|
github.com/compose-spec/compose-go/v2 v2.9.1
|
||||||
github.com/containerd/containerd v1.7.33
|
github.com/containerd/containerd v1.7.33
|
||||||
github.com/containerd/errdefs v1.0.0
|
github.com/containerd/errdefs v1.0.0
|
||||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5
|
|
||||||
github.com/distribution/reference v0.6.0
|
github.com/distribution/reference v0.6.0
|
||||||
github.com/docker/cli v28.5.1+incompatible
|
github.com/docker/cli v28.5.1+incompatible
|
||||||
github.com/docker/compose/v2 v2.40.3
|
github.com/docker/compose/v2 v2.40.3
|
||||||
|
|||||||
@@ -239,8 +239,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5 h1:RAV05c0xOkJ3dZGS0JFybxFKZ2WMLabgx3uXnd7rpGs=
|
|
||||||
github.com/dchest/uniuri v0.0.0-20200228104902-7aecb25e1fe5/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
|
|
||||||
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
|
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
|
||||||
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
|
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
|
||||||
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
github.com/denisenkom/go-mssqldb v0.0.0-20191128021309-1d7a30a10f73/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
|
||||||
|
|||||||
@@ -33,6 +33,18 @@ func int64n(max int64, fips bool) int64 {
|
|||||||
return i.Int64()
|
return i.Int64()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const alphanumericChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
|
|
||||||
|
// String returns a random alphanumeric string of length n.
|
||||||
|
func String(n int) string {
|
||||||
|
b := make([]byte, n)
|
||||||
|
for i := range b {
|
||||||
|
b[i] = alphanumericChars[int64n(int64(len(alphanumericChars)), true)]
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
func Float64() float64 {
|
func Float64() float64 {
|
||||||
return randomFloat64(fips.FIPSMode())
|
return randomFloat64(fips.FIPSMode())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package librand
|
package librand
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/portainer/portainer/pkg/fips"
|
"github.com/portainer/portainer/pkg/fips"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -49,6 +52,23 @@ func TestInternalIntn(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestString(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
const iterations = 1000
|
||||||
|
|
||||||
|
seen := make(map[string]bool, iterations)
|
||||||
|
for range iterations {
|
||||||
|
s := String(16)
|
||||||
|
|
||||||
|
require.Len(t, s, 16)
|
||||||
|
require.Empty(t, strings.Trim(s, alphanumericChars))
|
||||||
|
require.False(t, seen[s])
|
||||||
|
|
||||||
|
seen[s] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFloat64(t *testing.T) {
|
func TestFloat64(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
f := Float64()
|
f := Float64()
|
||||||
|
|||||||
Reference in New Issue
Block a user