forked from coreos/ignition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
invalid_hash.go
103 lines (95 loc) · 2.63 KB
/
invalid_hash.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright 2017 CoreOS, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package files
import (
"github.com/coreos/ignition/tests/register"
"github.com/coreos/ignition/tests/types"
)
func init() {
register.Register(register.NegativeTest, InvalidHash())
register.Register(register.NegativeTest, InvalidHashFromHTTPURL())
}
func InvalidHash() types.Test {
name := "Invalid File Hash"
in := types.GetBaseDisk()
out := in
mntDevices := []types.MntDevice{
{
Label: "EFI-SYSTEM",
Substitution: "$DEVICE",
},
}
config := `{
"ignition": {"version": "$version" },
"storage": {
"filesystems": [{
"mount": {
"device": "$DEVICE",
"format": "ext4",
"create": {
"force": true
}},
"name": "test"}],
"files": [{
"filesystem": "test",
"path": "/ignition/test",
"contents": {
"source": "data:,asdf", "verification": {"hash": "sha512-1a04c76c17079cd99e688ba4f1ba095b927d3fecf2b1e027af361dfeafb548f7f5f6fdd675aaa2563950db441d893ca77b0c3e965cdcb891784af96e330267d7"}}
}]}
}`
configMinVersion := "2.0.0"
return types.Test{
Name: name,
In: in,
Out: out,
MntDevices: mntDevices,
Config: config,
ConfigMinVersion: configMinVersion,
}
}
func InvalidHashFromHTTPURL() types.Test {
name := "Invalid File Hash from HTTP URL"
in := types.GetBaseDisk()
out := in
config := `{
"ignition": { "version": "$version" },
"storage": {
"files": [{
"filesystem": "root",
"path": "/foo/bar",
"contents": {
"source": "http://127.0.0.1:8080/contents",
"verification": {"hash": "sha512-807e8ff949e61d23f5ee42a629ec96e9fc526b62f030cd70ba2cd5b9d97935461eacc29bf58bcd0426e9e1fdb0eda939603ed52c9c06d0712208a15cd582c60e"}
}
}]
}
}`
configMinVersion := "2.0.0"
out[0].Partitions.AddFiles("ROOT", []types.File{
{
Node: types.Node{
Name: "bar",
Directory: "foo",
},
Contents: "asdf\nfdsa",
},
})
return types.Test{
Name: name,
In: in,
Out: out,
Config: config,
ConfigMinVersion: configMinVersion,
}
}