File: t_shacrypt_test.go

package info (click to toggle)
golang-github-go-crypt-crypt 0.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 516 kB
  • sloc: makefile: 4
file content (73 lines) | stat: -rwxr-xr-x 1,695 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package crypt

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSHACRYPTOutputsMKPASSWD(t *testing.T) {
	testcCases := []struct {
		name     string
		have     string
		expected string
		valid    bool
		err      string
	}{
		{
			"ShouldValidatePasswordWithOmittedRoundsSHA256",
			"$5$4X/QmdRP6q7Ilhpc$2sperIXN6jawEYd8a8arineQHqYIEGURjZGdD4H4xs8",
			password,
			true,
			"",
		},
		{
			"ShouldNotValidatePasswordWithOmittedRoundsSHA256",
			"$5$4X/QmdRP6q7Ilhpc$2sperIXN6jawEYd8a8arineQHqYIEGURjZGdD4H4xs8",
			wrongPassword,
			false,
			"",
		},
		{
			"ShouldValidatePasswordWithOmittedRoundsSHA512",
			"$6$rB2PL49BuajVczWm$sA.XUPEt/j6k4kFnO58EDKsEU8rXau47.eSH6lpqc/tgC9Y0BbYcG7H3.KmMMpthWMcip/xmDn83nTUXK5Vp90",
			password,
			true,
			"",
		},
		{
			"ShouldNotValidatePasswordWithOmittedRoundsSHA512",
			"$6$rB2PL49BuajVczWm$sA.XUPEt/j6k4kFnO58EDKsEU8rXau47.eSH6lpqc/tgC9Y0BbYcG7H3.KmMMpthWMcip/xmDn83nTUXK5Vp90",
			wrongPassword,
			false,
			"",
		},
		{
			"ShouldNotValidatePasswordWithRoundsSHA512",
			"$6$rounds=1000$rB2PL49BuajVczWm$sA.XUPEt/j6k4kFnO58EDKsEU8rXau47.eSH6lpqc/tgC9Y0BbYcG7H3.KmMMpthWMcip/xmDn83nTUXK5Vp90",
			wrongPassword,
			false,
			"",
		},
		{
			"ShouldValidatePasswordWithRoundsSHA512",
			"$6$rounds=1000$eG49klxUKySvBpju$.1paw1pj51FdmvNAnsNoX8lyHMdH/S74DfkZnWWTOnGI9keTp/DXjR9ro5kJrncPSF5fc.krAwdkBxc4C8kSU1",
			password,
			true,
			"",
		},
	}

	for _, tc := range testcCases {
		t.Run(tc.name, func(t *testing.T) {
			valid, err := CheckPassword(tc.expected, tc.have)

			assert.Equal(t, tc.valid, valid)
			if len(tc.err) == 0 {
				assert.NoError(t, err)
			} else {
				assert.EqualError(t, err, tc.err)
			}
		})
	}
}