File: wire_test.go

package info (click to toggle)
golang-github-hiddeco-sshsig 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 176 kB
  • sloc: makefile: 17
file content (61 lines) | stat: -rw-r--r-- 1,320 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
package sshsig

import (
	"testing"

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

func Test_signedData_Marshal(t *testing.T) {
	t.Run("has magic preamble", func(t *testing.T) {
		s := signedData{}
		m := s.Marshal()
		assert.Equal(t, magicPreamble[:], m[:6])
	})
}

func Test_blob_Valid(t *testing.T) {
	t.Run("unsupported version", func(t *testing.T) {
		b := blob{
			Version: 0,
		}
		assert.ErrorIs(t, b.Validate(), ErrUnsupportedSignatureVersion)
	})

	t.Run("invalid magic preamble", func(t *testing.T) {
		b := blob{
			Version:       sigVersion,
			MagicPreamble: [6]byte{'a', 'b', 'c', 'd', 'e', 'f'},
		}
		assert.ErrorIs(t, b.Validate(), ErrInvalidMagicPreamble)
	})

	t.Run("unsupported hash algorithm", func(t *testing.T) {
		b := blob{
			Version:       sigVersion,
			MagicPreamble: magicPreamble,
			HashAlgorithm: "foo",
		}
		assert.ErrorIs(t, b.Validate(), ErrUnsupportedHashAlgorithm)
	})

	t.Run("valid", func(t *testing.T) {
		b := blob{
			Version:       sigVersion,
			MagicPreamble: magicPreamble,
			HashAlgorithm: "sha256",
		}
		assert.NoError(t, b.Validate())
	})
}

func Test_blob_Marshal(t *testing.T) {
	t.Run("has magic preamble", func(t *testing.T) {
		b := blob{
			Version:       1,
			MagicPreamble: magicPreamble,
		}
		m := b.Marshal()
		assert.Equal(t, magicPreamble[:], m[:6])
	})
}