This repository has been archived by the owner on Mar 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add range syntax sugar for secret generation
Add the ability to specify ranges "A-Z", "a-z", and "0-9" when providing arguments for basic and token type secrets. Signed-off-by: Nick Hale <[email protected]>
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package secrets | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInflateRanges(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
want string | ||
}{ | ||
{ | ||
name: "", | ||
want: "", | ||
}, | ||
{ | ||
name: "-", | ||
want: "-", | ||
}, | ||
{ | ||
name: "A-", | ||
want: "-A", | ||
}, | ||
{ | ||
name: "A-A", | ||
want: "A", | ||
}, | ||
{ | ||
name: "A-Z", | ||
want: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
}, | ||
{ | ||
name: "Z-A", | ||
want: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
}, | ||
{ | ||
name: "A-z", | ||
want: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "z-A", | ||
want: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "a-z", | ||
want: "abcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "z-a", | ||
want: "abcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "0-9", | ||
want: "0123456789", | ||
}, | ||
{ | ||
name: "9-0", | ||
want: "0123456789", | ||
}, | ||
{ | ||
name: "0-9A-Z", | ||
want: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
}, | ||
{ | ||
name: "A-Z0-9", | ||
want: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
}, | ||
{ | ||
name: "A-Za-z0-9", | ||
want: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", | ||
}, | ||
{ | ||
name: "!#$%&*+-0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ^_abcdefghijklmnopqrstuvwxyz", | ||
want: "!#$%&*+-0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ^_abcdefghijklmnopqrstuvwxyz", | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert.Equal(t, tt.want, inflateRanges(tt.name)) | ||
}) | ||
} | ||
} |