25
25
hostnqn8 = "nqn.2014-08.org.nvmexpress:uuid:22207d09-d8af-4ed2-84ec-a6d80b0cf7f2"
26
26
hostnqn9 = "nqn.2014-08.org.nvmexpress:uuid:22207d09-d8af-4ed2-84ec-a6d80b0cf7f3"
27
27
hostnqn10 = "nqn.2014-08.org.nvmexpress:uuid:22207d09-d8af-4ed2-84ec-a6d80b0cf7f4"
28
- hostnqn11 = "nqn.2014-08.org.nvmexpress:uuid:22207d09-d8af-4ed2-84ec-a6d80b0cf7f5"
29
- hostnqn12 = "nqn.2014-08.org.nvmexpress:uuid:22207d09-d8af-4ed2-84ec-a6d80b0cf7f6"
30
28
31
29
hostpsk = "NVMeTLSkey-1:01:YzrPElk4OYy1uUERriPwiiyEJE/+J5ckYpLB+5NHMsR2iBuT:"
32
30
hostpsk2 = "NVMeTLSkey-1:02:FTFds4vH4utVcfrOforxbrWIgv+Qq4GQHgMdWwzDdDxE1bAqK2mOoyXxmbJxGeueEVVa/Q==:"
@@ -123,18 +121,14 @@ def test_create_not_secure(caplog, gateway):
123
121
124
122
def test_create_secure_list (caplog , gateway ):
125
123
caplog .clear ()
126
- cli (["host" , "add" , "--subsystem" , subsystem , "--host-nqn" , hostnqn8 , hostnqn9 , hostnqn10 , "--psk" , hostpsk5 , hostpsk6 , hostpsk7 , hostpsk ])
127
- assert f"There are more PSK values than hosts, will ignore redundant values" in caplog .text
128
- assert f"Adding host { hostnqn8 } to { subsystem } : Successful" in caplog .text
129
- assert f"Adding host { hostnqn9 } to { subsystem } : Successful" in caplog .text
130
- assert f"Adding host { hostnqn10 } to { subsystem } : Successful" in caplog .text
131
-
132
- def test_create_secure_list_missing_psk (caplog , gateway ):
133
- caplog .clear ()
134
- cli (["host" , "add" , "--subsystem" , subsystem , "--host-nqn" , hostnqn11 , hostnqn12 , "--psk" , hostpsk8 ])
135
- assert f"Adding host { hostnqn11 } to { subsystem } : Successful" in caplog .text
136
- assert f"Adding host { hostnqn12 } to { subsystem } : Successful" in caplog .text
137
- assert f"There are more hosts than PSK values, will assume empty PSK values" in caplog .text
124
+ rc = 0
125
+ try :
126
+ cli (["host" , "add" , "--subsystem" , subsystem , "--host-nqn" , hostnqn8 , hostnqn9 , hostnqn10 , "--psk" , hostpsk ])
127
+ except SystemExit as sysex :
128
+ rc = int (str (sysex ))
129
+ pass
130
+ assert rc == 2
131
+ assert f"error: Can't have more than one host NQN when PSK keys are used" in caplog .text
138
132
139
133
def test_create_secure_junk_key (caplog , gateway ):
140
134
caplog .clear ()
@@ -150,16 +144,14 @@ def test_create_secure_no_key(caplog, gateway):
150
144
rc = int (str (sysex ))
151
145
pass
152
146
assert rc == 2
153
- assert f"error: argument --psk: expected at least one argument" in caplog .text
147
+ assert f"error: argument --psk: expected one argument" in caplog .text
154
148
155
149
def test_list_psk_hosts (caplog , gateway ):
156
150
caplog .clear ()
157
151
hosts = cli_test (["host" , "list" , "--subsystem" , subsystem ])
158
152
found = 0
159
- assert len (hosts .hosts ) == 10
153
+ assert len (hosts .hosts ) == 5
160
154
for h in hosts .hosts :
161
- assert h .nqn != hostnqn3
162
- assert h .nqn != hostnqn5
163
155
if h .nqn == hostnqn :
164
156
found += 1
165
157
assert h .use_psk
@@ -175,29 +167,20 @@ def test_list_psk_hosts(caplog, gateway):
175
167
elif h .nqn == hostnqn7 :
176
168
found += 1
177
169
assert not h .use_psk
178
- elif h .nqn == hostnqn8 :
179
- found += 1
180
- assert h .use_psk
181
- elif h .nqn == hostnqn9 :
182
- found += 1
183
- assert h .use_psk
184
- elif h .nqn == hostnqn10 :
185
- found += 1
186
- assert h .use_psk
187
- elif h .nqn == hostnqn11 :
188
- found += 1
189
- assert h .use_psk
190
- elif h .nqn == hostnqn12 :
191
- found += 1
192
- assert not h .use_psk
193
170
else :
194
171
assert False
195
- assert found == 10
172
+ assert found == 5
196
173
197
174
def test_allow_any_host_with_psk (caplog , gateway ):
198
175
caplog .clear ()
199
- cli (["host" , "add" , "--subsystem" , subsystem , "--host-nqn" , "*" , "--psk" , hostpsk ])
200
- assert f"PSK is only allowed for specific hosts, ignoring PSK value \" { hostpsk } \" " in caplog .text
176
+ rc = 0
177
+ try :
178
+ cli (["host" , "add" , "--subsystem" , subsystem , "--host-nqn" , "*" , "--psk" , hostpsk ])
179
+ except SystemExit as sysex :
180
+ rc = int (str (sysex ))
181
+ pass
182
+ assert rc == 2
183
+ assert f"error: PSK is only allowed for specific hosts" in caplog .text
201
184
202
185
def test_list_listeners (caplog , gateway ):
203
186
caplog .clear ()
0 commit comments