-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdevice_real_camera_test.go
More file actions
597 lines (537 loc) · 22.5 KB
/
device_real_camera_test.go
File metadata and controls
597 lines (537 loc) · 22.5 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
package onvif
import (
"context"
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
// Test device information from real camera:
// Manufacturer: Bosch
// Model: FLEXIDOME indoor 5100i IR
// Firmware: 8.71.0066
// Serial Number: 404754734001050102
// Hardware ID: F000B543
// TestGetDeviceInformation_Bosch tests GetDeviceInformation with real camera response.
func TestGetDeviceInformation_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetDeviceInformationResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:Manufacturer>Bosch</tds:Manufacturer>
<tds:Model>FLEXIDOME indoor 5100i IR</tds:Model>
<tds:FirmwareVersion>8.71.0066</tds:FirmwareVersion>
<tds:SerialNumber>404754734001050102</tds:SerialNumber>
<tds:HardwareId>F000B543</tds:HardwareId>
</tds:GetDeviceInformationResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetDeviceInformation") {
t.Errorf("Request should contain GetDeviceInformation, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
info, err := client.GetDeviceInformation(ctx)
if err != nil {
t.Fatalf("GetDeviceInformation() failed: %v", err)
}
// Validate response matches real camera
if info.Manufacturer != "Bosch" {
t.Errorf("Expected Manufacturer=Bosch (Bosch FLEXIDOME), got %s", info.Manufacturer)
}
if info.Model != "FLEXIDOME indoor 5100i IR" {
t.Errorf("Expected Model=FLEXIDOME indoor 5100i IR (Bosch FLEXIDOME), got %s", info.Model)
}
if info.FirmwareVersion != "8.71.0066" {
t.Errorf("Expected FirmwareVersion=8.71.0066 (Bosch FLEXIDOME), got %s", info.FirmwareVersion)
}
if info.SerialNumber != "404754734001050102" {
t.Errorf("Expected SerialNumber=404754734001050102 (Bosch FLEXIDOME), got %s", info.SerialNumber)
}
if info.HardwareID != "F000B543" {
t.Errorf("Expected HardwareID=F000B543 (Bosch FLEXIDOME), got %s", info.HardwareID)
}
}
// TestGetCapabilities_Bosch tests GetCapabilities with real camera response.
func TestGetCapabilities_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetCapabilitiesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:Capabilities>
<tds:Device>
<tds:XAddr>http://192.168.1.201/onvif/device_service</tds:XAddr>
<tds:Network>
<tt:IPFilter xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:IPFilter>
<tt:ZeroConfiguration xmlns:tt="http://www.onvif.org/ver10/schema">true</tt:ZeroConfiguration>
<tt:IPVersion6 xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:IPVersion6>
<tt:DynDNS xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:DynDNS>
</tds:Network>
<tds:System>
<tt:DiscoveryResolve xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:DiscoveryResolve>
<tt:DiscoveryBye xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:DiscoveryBye>
<tt:RemoteDiscovery xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:RemoteDiscovery>
<tt:SystemBackup xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:SystemBackup>
<tt:SystemLogging xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:SystemLogging>
<tt:FirmwareUpgrade xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:FirmwareUpgrade>
<tt:SupportedVersions xmlns:tt="http://www.onvif.org/ver10/schema">1 2</tt:SupportedVersions>
</tds:System>
<tds:IO>
<tt:InputConnectors xmlns:tt="http://www.onvif.org/ver10/schema">1</tt:InputConnectors>
<tt:RelayOutputs xmlns:tt="http://www.onvif.org/ver10/schema">1</tt:RelayOutputs>
</tds:IO>
<tds:Security>
<tt:TLS1.1 xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:TLS1.1>
<tt:TLS1.2 xmlns:tt="http://www.onvif.org/ver10/schema">true</tt:TLS1.2>
<tt:OnboardKeyGeneration xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:OnboardKeyGeneration>
<tt:AccessPolicyConfig xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:AccessPolicyConfig>
<tt:X509Token xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:X509Token>
<tt:SAMLToken xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:SAMLToken>
<tt:KerberosToken xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:KerberosToken>
<tt:RELToken xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:RELToken>
</tds:Security>
</tds:Device>
<tds:Media>
<tds:XAddr>http://192.168.1.201/onvif/media_service</tds:XAddr>
<tds:StreamingCapabilities>
<tt:RTPMulticast xmlns:tt="http://www.onvif.org/ver10/schema">true</tt:RTPMulticast>
<tt:RTP_TCP xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:RTP_TCP>
<tt:RTP_RTSP_TCP xmlns:tt="http://www.onvif.org/ver10/schema">true</tt:RTP_RTSP_TCP>
</tds:StreamingCapabilities>
</tds:Media>
<tds:Imaging>
<tds:XAddr>http://192.168.1.201/onvif/imaging_service</tds:XAddr>
</tds:Imaging>
<tds:Events>
<tds:XAddr>http://192.168.1.201/onvif/event_service</tds:XAddr>
<tds:WSSubscriptionPolicySupport>false</tds:WSSubscriptionPolicySupport>
<tds:WSPullPointSupport>false</tds:WSPullPointSupport>
<tds:WSPausableSubscriptionSupport>false</tds:WSPausableSubscriptionSupport>
</tds:Events>
<tds:Analytics>
<tds:XAddr>http://192.168.1.201/onvif/analytics_service</tds:XAddr>
<tds:RuleSupport>true</tds:RuleSupport>
<tds:AnalyticsModuleSupport>true</tds:AnalyticsModuleSupport>
</tds:Analytics>
</tds:Capabilities>
</tds:GetCapabilitiesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetCapabilities") {
t.Errorf("Request should contain GetCapabilities, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
caps, err := client.GetCapabilities(ctx)
if err != nil {
t.Fatalf("GetCapabilities() failed: %v", err)
}
// Validate response matches real camera
if caps.Device == nil {
t.Fatal("Expected Device capabilities from Bosch FLEXIDOME")
}
if !strings.Contains(caps.Device.XAddr, "device_service") {
t.Errorf("Expected device service XAddr from Bosch FLEXIDOME, got %s", caps.Device.XAddr)
}
if caps.Device.Network == nil {
t.Fatal("Expected Network capabilities from Bosch FLEXIDOME")
}
if !caps.Device.Network.ZeroConfiguration {
t.Error("Expected ZeroConfiguration=true from Bosch FLEXIDOME")
}
if caps.Device.Security == nil {
t.Fatal("Expected Security capabilities from Bosch FLEXIDOME")
}
if !caps.Device.Security.TLS12 {
t.Error("Expected TLS12=true from Bosch FLEXIDOME")
}
if caps.Media == nil {
t.Fatal("Expected Media capabilities from Bosch FLEXIDOME")
}
if !strings.Contains(caps.Media.XAddr, "media_service") {
t.Errorf("Expected media service XAddr from Bosch FLEXIDOME, got %s", caps.Media.XAddr)
}
if caps.Media.StreamingCapabilities == nil {
t.Fatal("Expected StreamingCapabilities from Bosch FLEXIDOME")
}
if !caps.Media.StreamingCapabilities.RTPMulticast {
t.Error("Expected RTPMulticast=true from Bosch FLEXIDOME")
}
}
// TestGetServices_Bosch tests GetServices with real camera response.
func TestGetServices_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetServicesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:Service>
<tds:Namespace>http://www.onvif.org/ver10/device/wsdl</tds:Namespace>
<tds:XAddr>http://192.168.1.201/onvif/device_service</tds:XAddr>
<tds:Version>
<tt:Major xmlns:tt="http://www.onvif.org/ver10/schema">1</tt:Major>
<tt:Minor xmlns:tt="http://www.onvif.org/ver10/schema">3</tt:Minor>
</tds:Version>
</tds:Service>
<tds:Service>
<tds:Namespace>http://www.onvif.org/ver10/media/wsdl</tds:Namespace>
<tds:XAddr>http://192.168.1.201/onvif/media_service</tds:XAddr>
<tds:Version>
<tt:Major xmlns:tt="http://www.onvif.org/ver10/schema">1</tt:Major>
<tt:Minor xmlns:tt="http://www.onvif.org/ver10/schema">3</tt:Minor>
</tds:Version>
</tds:Service>
<tds:Service>
<tds:Namespace>http://www.onvif.org/ver10/events/wsdl</tds:Namespace>
<tds:XAddr>http://192.168.1.201/onvif/event_service</tds:XAddr>
<tds:Version>
<tt:Major xmlns:tt="http://www.onvif.org/ver10/schema">1</tt:Major>
<tt:Minor xmlns:tt="http://www.onvif.org/ver10/schema">4</tt:Minor>
</tds:Version>
</tds:Service>
</tds:GetServicesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetServices") {
t.Errorf("Request should contain GetServices, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
services, err := client.GetServices(ctx, false)
if err != nil {
t.Fatalf("GetServices() failed: %v", err)
}
// Validate response matches real camera
if len(services) == 0 {
t.Fatal("Expected at least one service from Bosch FLEXIDOME")
}
// Check for Device service
foundDevice := false
for _, svc := range services {
if svc.Namespace == "http://www.onvif.org/ver10/device/wsdl" {
foundDevice = true
if svc.Version.Major != 1 || svc.Version.Minor != 3 {
t.Errorf("Expected Device service version 1.3 (Bosch FLEXIDOME), got %d.%d", svc.Version.Major, svc.Version.Minor)
}
if !strings.Contains(svc.XAddr, "device_service") {
t.Errorf("Expected device_service in XAddr (Bosch FLEXIDOME), got %s", svc.XAddr)
}
}
}
if !foundDevice {
t.Error("Expected Device service from Bosch FLEXIDOME")
}
}
// TestGetServiceCapabilities_Bosch tests GetServiceCapabilities with real camera response.
func TestGetServiceCapabilities_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
// Note: Uses attributes, not child elements
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetServiceCapabilitiesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:Capabilities>
<tds:Network IPFilter="false" ZeroConfiguration="true" IPVersion6="false" DynDNS="false"/>
<tds:System DiscoveryResolve="false" DiscoveryBye="false" RemoteDiscovery="false" SystemBackup="false" SystemLogging="false" FirmwareUpgrade="false"/>
<tds:Security TLS1.1="false" TLS1.2="true" OnboardKeyGeneration="false" AccessPolicyConfig="false"/>
</tds:Capabilities>
</tds:GetServiceCapabilitiesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetServiceCapabilities") {
t.Errorf("Request should contain GetServiceCapabilities, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
caps, err := client.GetServiceCapabilities(ctx)
if err != nil {
t.Fatalf("GetServiceCapabilities() failed: %v", err)
}
// Validate response matches real camera
if caps.Network == nil {
t.Fatal("Expected Network capabilities from Bosch FLEXIDOME")
}
if !caps.Network.ZeroConfiguration {
t.Error("Expected ZeroConfiguration=true from Bosch FLEXIDOME")
}
if caps.Security == nil {
t.Fatal("Expected Security capabilities from Bosch FLEXIDOME")
}
if !caps.Security.TLS12 {
t.Error("Expected TLS12=true from Bosch FLEXIDOME")
}
}
// TestGetSystemDateAndTime_Bosch tests GetSystemDateAndTime with real camera response.
func TestGetSystemDateAndTime_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetSystemDateAndTimeResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:SystemDateAndTime>
<tt:DateTimeType xmlns:tt="http://www.onvif.org/ver10/schema">Manual</tt:DateTimeType>
<tt:DaylightSaving xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:DaylightSaving>
<tt:TimeZone>
<tt:TZ xmlns:tt="http://www.onvif.org/ver10/schema">CST6CDT</tt:TZ>
</tt:TimeZone>
<tt:UTCDateTime>
<tt:Time>
<tt:Hour xmlns:tt="http://www.onvif.org/ver10/schema">4</tt:Hour>
<tt:Minute xmlns:tt="http://www.onvif.org/ver10/schema">56</tt:Minute>
<tt:Second xmlns:tt="http://www.onvif.org/ver10/schema">14</tt:Second>
</tt:Time>
<tt:Date>
<tt:Year xmlns:tt="http://www.onvif.org/ver10/schema">2025</tt:Year>
<tt:Month xmlns:tt="http://www.onvif.org/ver10/schema">12</tt:Month>
<tt:Day xmlns:tt="http://www.onvif.org/ver10/schema">2</tt:Day>
</tt:Date>
</tt:UTCDateTime>
</tds:SystemDateAndTime>
</tds:GetSystemDateAndTimeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetSystemDateAndTime") {
t.Errorf("Request should contain GetSystemDateAndTime, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
dateTime, err := client.GetSystemDateAndTime(ctx)
if err != nil {
t.Fatalf("GetSystemDateAndTime() failed: %v", err)
}
// GetSystemDateAndTime returns interface{} - just verify no error
// The actual structure depends on the camera's response format
_ = dateTime // Acknowledge we received a response
}
// TestGetHostname_Bosch tests GetHostname with real camera response.
func TestGetHostname_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetHostnameResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:HostnameInformation>
<tt:FromDHCP xmlns:tt="http://www.onvif.org/ver10/schema">false</tt:FromDHCP>
<tt:Name xmlns:tt="http://www.onvif.org/ver10/schema">BOSCH-404754734001050102</tt:Name>
</tds:HostnameInformation>
</tds:GetHostnameResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetHostname") {
t.Errorf("Request should contain GetHostname, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
hostname, err := client.GetHostname(ctx)
if err != nil {
t.Fatalf("GetHostname() failed: %v", err)
}
// Validate response matches real camera
if hostname == nil {
t.Fatal("Expected HostnameInformation from Bosch FLEXIDOME")
}
if !strings.Contains(hostname.Name, "BOSCH") {
t.Errorf("Expected hostname to contain BOSCH (Bosch FLEXIDOME), got %s", hostname.Name)
}
if hostname.FromDHCP {
t.Error("Expected FromDHCP=false from Bosch FLEXIDOME")
}
}
// TestGetScopes_Bosch tests GetScopes with real camera response.
func TestGetScopes_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetScopesResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:Scopes>
<tt:ScopeDef xmlns:tt="http://www.onvif.org/ver10/schema">Fixed</tt:ScopeDef>
<tt:ScopeItem xmlns:tt="http://www.onvif.org/ver10/schema">onvif://www.onvif.org/name/BOSCH-404754734001050102</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef xmlns:tt="http://www.onvif.org/ver10/schema">Fixed</tt:ScopeDef>
<tt:ScopeItem xmlns:tt="http://www.onvif.org/ver10/schema">onvif://www.onvif.org/location/</tt:ScopeItem>
</tds:Scopes>
<tds:Scopes>
<tt:ScopeDef xmlns:tt="http://www.onvif.org/ver10/schema">Fixed</tt:ScopeDef>
<tt:ScopeItem xmlns:tt="http://www.onvif.org/ver10/schema">onvif://www.onvif.org/hardware/F000B543</tt:ScopeItem>
</tds:Scopes>
</tds:GetScopesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetScopes") {
t.Errorf("Request should contain GetScopes, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
scopes, err := client.GetScopes(ctx)
if err != nil {
t.Fatalf("GetScopes() failed: %v", err)
}
// Validate response matches real camera
if len(scopes) == 0 {
t.Fatal("Expected at least one scope from Bosch FLEXIDOME")
}
// Check for hardware scope
foundHardware := false
for _, scope := range scopes {
if strings.Contains(scope.ScopeItem, "hardware") {
foundHardware = true
if !strings.Contains(scope.ScopeItem, "F000B543") {
t.Errorf("Expected hardware ID F000B543 in scope (Bosch FLEXIDOME), got %s", scope.ScopeItem)
}
}
}
if !foundHardware {
t.Error("Expected hardware scope from Bosch FLEXIDOME")
}
}
// TestGetUsers_Bosch tests GetUsers with real camera response.
func TestGetUsers_Bosch(t *testing.T) {
// Real SOAP response from Bosch FLEXIDOME indoor 5100i IR (FW: 8.71.0066)
realResponse := `<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
<tds:GetUsersResponse xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
<tds:User>
<tt:Username xmlns:tt="http://www.onvif.org/ver10/schema">service</tt:Username>
<tt:UserLevel xmlns:tt="http://www.onvif.org/ver10/schema">Administrator</tt:UserLevel>
</tds:User>
</tds:GetUsersResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body)
if err != nil {
t.Fatalf("Failed to read request body: %v", err)
}
bodyStr := string(body)
if !strings.Contains(bodyStr, "GetUsers") {
t.Errorf("Request should contain GetUsers, got: %s", bodyStr)
}
w.Header().Set("Content-Type", "application/soap+xml")
w.WriteHeader(http.StatusOK)
w.Write([]byte(realResponse))
}))
defer server.Close()
client, err := NewClient(server.URL, WithCredentials("service", "Service.1234"))
if err != nil {
t.Fatalf("NewClient() failed: %v", err)
}
ctx := context.Background()
users, err := client.GetUsers(ctx)
if err != nil {
t.Fatalf("GetUsers() failed: %v", err)
}
// Validate response matches real camera
if len(users) == 0 {
t.Fatal("Expected at least one user from Bosch FLEXIDOME")
}
if users[0].Username != "service" {
t.Errorf("Expected username=service (Bosch FLEXIDOME), got %s", users[0].Username)
}
if users[0].UserLevel != "Administrator" {
t.Errorf("Expected UserLevel=Administrator (Bosch FLEXIDOME), got %s", users[0].UserLevel)
}
}