-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommon.hs
More file actions
130 lines (119 loc) · 4.4 KB
/
Copy pathCommon.hs
File metadata and controls
130 lines (119 loc) · 4.4 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
-- SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
--
-- SPDX-License-Identifier: MPL-2.0
module Common.Common
( unit_incorrect_backend_name
, unit_incorrect_field_name_fromJSONKey
, unit_incorrect_field_name_fromHttpApiData
, unit_incorrect_tag_name_fromJSON
, unit_incorrect_tag_name_fromHttpApiData
, unit_incorrect_path_segment_fromHttpApiData
) where
import Control.Exception
import Data.Aeson (encode)
import Data.Aeson.QQ.Simple (aesonQQ)
import Data.ByteString.Lazy qualified as LBS
import Data.Text
import Network.HTTP.Client (Response(responseStatus))
import Network.HTTP.Req
import Network.HTTP.Types (status400)
import Test.Tasty.HUnit
import Utils
unit_incorrect_backend_name :: IO ()
unit_incorrect_backend_name = cofferTest do
try @HttpException
(executeCommandWithHeader
errHeader
POST
["create"]
(ReqBodyJson emptyNewEntry)
ignoreResponse
("path" =: ("entry" :: Text))
) >>= unwrapStatusCodeError \response bs -> do
bs @?= "Error parsing header Coffer-Backend failed: Error in $.name: Backend name can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_;'"
responseStatus response @?= status400
where
emptyNewEntry =
[aesonQQ|
{
"fields": { },
"tags": []
}
|]
errHeader = LBS.toStrict . encode $
[aesonQQ|
{
"type" : "vault-kv",
"name" : "vault-local#",
"address" : "localhost:8212",
"mount" : "secret",
"token" : "root"
}
|]
unit_incorrect_field_name_fromJSONKey :: IO()
unit_incorrect_field_name_fromJSONKey = cofferTest do
try @HttpException
(executeCommand
POST
["create"]
(ReqBodyJson emptyNewEntry)
ignoreResponse
("path" =: ("entry" :: Text))
) >>= unwrapStatusCodeError \response bs -> do
bs @?= "Error in $.fields['fieldname:.']: Field name can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_;'"
responseStatus response @?= status400
where
emptyNewEntry =
[aesonQQ|
{
"fields":
{
"fieldname:." :
{
"contents" : "contents",
"visibility" : "public"
}
},
"tags": []
}
|]
unit_incorrect_field_name_fromHttpApiData :: IO()
unit_incorrect_field_name_fromHttpApiData = cofferTest do
createEntry "entry"
try @HttpException ( setField "entry" "fieldname:." Nothing "contents" )
>>= unwrapStatusCodeError \response bs -> do
bs @?= "Error parsing query parameter field failed: Field name can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_;'"
responseStatus response @?= status400
unit_incorrect_tag_name_fromJSON :: IO()
unit_incorrect_tag_name_fromJSON = cofferTest do
try @HttpException
(executeCommand
POST
["create"]
(ReqBodyJson emptyNewEntry)
ignoreResponse
("path" =: ("entry" :: Text))
) >>= unwrapStatusCodeError \response bs -> do
bs @?= "Error in $.tags[0]: Tags can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_;'"
responseStatus response @?= status400
where
emptyNewEntry =
[aesonQQ|
{
"fields": {},
"tags": [ "tag:." ]
}
|]
unit_incorrect_tag_name_fromHttpApiData :: IO ()
unit_incorrect_tag_name_fromHttpApiData = cofferTest do
createEntry "tagged"
try @HttpException ( addOrRemoveTag POST "tagged" "tag:." )
>>= unwrapStatusCodeError \response bs -> do
bs @?= "Error parsing query parameter tag failed: Tags can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_;'"
responseStatus response @?= status400
unit_incorrect_path_segment_fromHttpApiData :: IO ()
unit_incorrect_path_segment_fromHttpApiData = cofferTest do
try @HttpException ( createEntry "entry:." )
>>= unwrapStatusCodeError \response bs -> do
bs @?= "Error parsing query parameter path failed: Path segments can only contain the following characters: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_'"
responseStatus response @?= status400