agntcy-slim-controller 0.6.2

Controller service and control API to configure the SLIM data plane through the control plane.
Documentation
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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
// Copyright AGNTCY Contributors (https://github.com/agntcy)
// SPDX-License-Identifier: Apache-2.0

use std::sync::Arc;

use serde::Deserialize;

use slim_auth::auth_provider::{AuthProvider, AuthVerifier};
use slim_config::auth::identity::{IdentityProviderConfig, IdentityVerifierConfig};
use slim_config::component::configuration::Configuration;
use slim_config::component::id::ID;
use slim_config::grpc::client::ClientConfig;
use slim_config::grpc::server::ServerConfig;
use slim_datapath::message_processing::MessageProcessor;

use crate::errors::ControllerError;
use crate::service::{ControlPlane, ControlPlaneSettings, from_server_config};

/// Configuration for the Control-Plane / Data-Plane component
#[derive(Debug, Clone, Deserialize, Default, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct Config {
    /// Controller GRPC server settings
    #[serde(default)]
    pub servers: Vec<ServerConfig>,

    /// Controller client config to connect to control plane
    #[serde(default)]
    pub clients: Vec<ClientConfig>,

    /// Token provider authentication configuration
    #[serde(default)]
    pub token_provider: IdentityProviderConfig,

    /// Token verifier authentication configuration
    #[serde(default)]
    pub token_verifier: IdentityVerifierConfig,

    /// How long to keep routing state after a server-side connection drops,
    /// waiting for the peer to reconnect before notifying the control plane.
    /// Accepts duration strings like "30s", "1s", "500ms".  Defaults to 30 s.
    #[serde(default)]
    pub recovery_ttl: Option<duration_string::DurationString>,
}

impl Config {
    /// Create a new Config instance with default values
    pub fn new() -> Self {
        Self::default()
    }

    pub fn is_default(&self) -> bool {
        self == &Self::default()
    }

    /// Create a new Config instance with the given servers
    pub fn with_servers(self, servers: Vec<ServerConfig>) -> Self {
        Self { servers, ..self }
    }

    /// Create a new Config instance with the given clients
    pub fn with_clients(self, clients: Vec<ClientConfig>) -> Self {
        Self { clients, ..self }
    }

    /// Set the token provider authentication configuration
    pub fn with_token_provider_auth(self, auth: IdentityProviderConfig) -> Self {
        Self {
            token_provider: auth,
            ..self
        }
    }

    /// Set the token verifier authentication configuration
    pub fn with_token_verifier_auth(self, auth: IdentityVerifierConfig) -> Self {
        Self {
            token_verifier: auth,
            ..self
        }
    }

    /// Get the list of server configurations
    pub fn servers(&self) -> &[ServerConfig] {
        &self.servers
    }

    /// Get the list of client configurations
    pub fn clients(&self) -> &[ClientConfig] {
        &self.clients
    }

    fn get_token_provider_auth(&self) -> Option<AuthProvider> {
        match &self.token_provider {
            IdentityProviderConfig::SharedSecret { id, data } => {
                AuthProvider::shared_secret_from_str(id, data).ok()
            }
            IdentityProviderConfig::StaticJwt(static_jwt_config) => {
                let provider = static_jwt_config
                    .build_static_token_provider()
                    .expect("Failed to build StaticTokenProvider");
                Some(AuthProvider::static_token(provider))
            }
            IdentityProviderConfig::Jwt(jwt_config) => {
                let provider = jwt_config
                    .get_provider()
                    .expect("Failed to build JwtTokenProvider");
                Some(AuthProvider::jwt_signer(provider))
            }
            #[cfg(not(target_family = "windows"))]
            IdentityProviderConfig::Spire(spire_config) => {
                let manager = spire_config
                    .create_provider()
                    .expect("Failed to build SpireIdentityManager");
                Some(AuthProvider::spire(manager))
            }
            IdentityProviderConfig::None => None,
        }
    }

    fn get_token_verifier_auth(&self) -> Option<AuthVerifier> {
        match &self.token_verifier {
            IdentityVerifierConfig::SharedSecret { id, data } => {
                AuthVerifier::shared_secret_from_str(id, data).ok()
            }
            IdentityVerifierConfig::Jwt(jwt_config) => {
                let verifier = jwt_config
                    .get_verifier()
                    .expect("Failed to build JwtTokenVerifier");
                Some(AuthVerifier::jwt_verifier(verifier))
            }
            #[cfg(not(target_family = "windows"))]
            IdentityVerifierConfig::Spire(spire_config) => {
                let manager = spire_config
                    .create_provider()
                    .expect("Failed to build SpireIdentityManager");
                Some(AuthVerifier::spire(manager))
            }
            IdentityVerifierConfig::None => None,
        }
    }

    /// Create a ControlPlane service instance from this configuration
    pub fn into_service(
        &self,
        id: ID,
        group_name: Option<String>,
        message_processor: Arc<MessageProcessor>,
        // List of server configurations for the dataplane services.
        // Used to extract connection type information required to connect to the node
        // (e.g., TLS settings). This information is used by the control plane.
        dataplane_servers: &[ServerConfig],
    ) -> ControlPlane {
        let auth_provider = self.get_token_provider_auth();
        let auth_verifier = self.get_token_verifier_auth();

        let connection_details = dataplane_servers.iter().map(from_server_config).collect();

        ControlPlane::new(ControlPlaneSettings {
            id,
            group_name,
            servers: self.servers.clone(),
            clients: self.clients.clone(),
            message_processor,
            auth_provider,
            auth_verifier,
            connection_details,
        })
    }
}

impl Configuration for Config {
    type Error = ControllerError;

    fn validate(&self) -> Result<(), Self::Error> {
        // Validate client and server configurations
        for server in self.servers.iter() {
            server.validate()?;
        }

        for client in &self.clients {
            client.validate()?;
        }

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use slim_config::auth::jwt::Config as JwtConfig;
    use slim_config::auth::static_jwt::Config as StaticJwtConfig;
    use slim_config::component::id::{ID, Kind};
    use slim_config::grpc::client::ClientConfig;
    use slim_config::grpc::server::ServerConfig;
    use slim_datapath::message_processing::MessageProcessor;
    use slim_testing::utils::TEST_VALID_SECRET;
    use std::sync::Arc;

    fn create_test_server_config() -> ServerConfig {
        ServerConfig::with_endpoint("127.0.0.1:50051")
            .with_tls_settings(slim_config::tls::server::TlsServerConfig::insecure())
    }

    fn create_test_client_config() -> ClientConfig {
        ClientConfig::with_endpoint("http://127.0.0.1:50051")
            .with_tls_setting(slim_config::tls::client::TlsClientConfig::insecure())
    }

    #[test]
    fn test_config_new() {
        let config = Config::new();
        assert!(config.servers.is_empty());
        assert!(config.clients.is_empty());
        assert_eq!(config.token_provider, IdentityProviderConfig::None);
        assert_eq!(config.token_verifier, IdentityVerifierConfig::None);
    }

    #[test]
    fn test_config_default() {
        let config = Config::default();
        assert!(config.servers.is_empty());
        assert!(config.clients.is_empty());
        assert_eq!(config.token_provider, IdentityProviderConfig::None);
        assert_eq!(config.token_verifier, IdentityVerifierConfig::None);
    }

    #[test]
    fn test_config_with_servers() {
        let server_config = create_test_server_config();
        let config = Config::new().with_servers(vec![server_config.clone()]);

        assert_eq!(config.servers.len(), 1);
        assert_eq!(config.servers[0], server_config);
        assert!(config.clients.is_empty());
    }

    #[test]
    fn test_config_with_clients() {
        let client_config = create_test_client_config();
        let config = Config::new().with_clients(vec![client_config.clone()]);

        assert_eq!(config.clients.len(), 1);
        assert_eq!(config.clients[0], client_config);
        assert!(config.servers.is_empty());
    }

    #[test]
    fn test_config_with_token_provider_auth_shared_secret() {
        let auth = IdentityProviderConfig::SharedSecret {
            id: "test-provider".to_string(),
            data: "test-secret".to_string(),
        };
        let config = Config::new().with_token_provider_auth(auth.clone());

        assert_eq!(config.token_provider, auth);
        assert_eq!(config.token_verifier, IdentityVerifierConfig::None);
    }

    #[test]
    fn test_config_with_token_provider_auth_static_jwt() {
        let static_jwt_config = StaticJwtConfig::with_file("test-key".to_string());
        let auth = IdentityProviderConfig::StaticJwt(static_jwt_config);
        let config = Config::new().with_token_provider_auth(auth.clone());

        assert_eq!(config.token_provider, auth);
    }

    #[test]
    fn test_config_with_token_provider_auth_jwt() {
        use slim_auth::jwt::{Algorithm, Key, KeyData, KeyFormat};
        use slim_config::auth::jwt::{Claims, JwtKey};
        use std::time::Duration;

        let claims = Claims::default();
        let duration = Duration::from_secs(3600);
        let key = JwtKey::Encoding(Key {
            algorithm: Algorithm::HS256,
            format: KeyFormat::Pem,
            key: KeyData::Data("test-secret".to_string()),
        });
        let jwt_config = JwtConfig::new(claims, duration, key);
        let auth = IdentityProviderConfig::Jwt(jwt_config);
        let config = Config::new().with_token_provider_auth(auth.clone());

        assert_eq!(config.token_provider, auth);
    }

    #[test]
    fn test_config_with_token_verifier_auth_shared_secret() {
        let auth = IdentityVerifierConfig::SharedSecret {
            id: "test-verifier".to_string(),
            data: "test-secret".to_string(),
        };
        let config = Config::new().with_token_verifier_auth(auth.clone());

        assert_eq!(config.token_verifier, auth);
        assert_eq!(config.token_provider, IdentityProviderConfig::None);
    }

    #[test]
    fn test_config_with_token_verifier_auth_jwt() {
        use slim_auth::jwt::{Algorithm, Key, KeyData, KeyFormat};
        use slim_config::auth::jwt::{Claims, JwtKey};
        use std::time::Duration;

        let claims = Claims::default();
        let duration = Duration::from_secs(3600);
        let key = JwtKey::Decoding(Key {
            algorithm: Algorithm::HS256,
            format: KeyFormat::Pem,
            key: KeyData::Data("test-secret".to_string()),
        });
        let jwt_config = JwtConfig::new(claims, duration, key);
        let auth = IdentityVerifierConfig::Jwt(jwt_config);
        let config = Config::new().with_token_verifier_auth(auth.clone());

        assert_eq!(config.token_verifier, auth);
    }

    #[test]
    fn test_config_servers_getter() {
        let server_config = create_test_server_config();
        let config = Config::new().with_servers(vec![server_config.clone()]);

        let servers = config.servers();
        assert_eq!(servers.len(), 1);
        assert_eq!(servers[0], server_config);
    }

    #[test]
    fn test_config_clients_getter() {
        let client_config = create_test_client_config();
        let config = Config::new().with_clients(vec![client_config.clone()]);

        let clients = config.clients();
        assert_eq!(clients.len(), 1);
        assert_eq!(clients[0], client_config);
    }

    #[test]
    fn test_config_chaining() {
        let server_config = create_test_server_config();
        let client_config = create_test_client_config();
        let provider_auth = IdentityProviderConfig::SharedSecret {
            id: "test-provider".to_string(),
            data: "provider-secret".to_string(),
        };
        let verifier_auth = IdentityVerifierConfig::SharedSecret {
            id: "test-verifier".to_string(),
            data: "verifier-secret".to_string(),
        };

        let config = Config::new()
            .with_servers(vec![server_config.clone()])
            .with_clients(vec![client_config.clone()])
            .with_token_provider_auth(provider_auth.clone())
            .with_token_verifier_auth(verifier_auth.clone());

        assert_eq!(config.servers.len(), 1);
        assert_eq!(config.clients.len(), 1);
        assert_eq!(config.token_provider, provider_auth);
        assert_eq!(config.token_verifier, verifier_auth);
    }

    #[test]
    fn test_config_validate_empty() {
        let config = Config::new();
        assert!(config.validate().is_ok());
    }

    #[test]
    fn test_config_validate_with_valid_servers_and_clients() {
        let server_config = create_test_server_config();
        let client_config = create_test_client_config();
        let config = Config::new()
            .with_servers(vec![server_config])
            .with_clients(vec![client_config]);

        assert!(config.validate().is_ok());
    }

    #[test]
    fn test_token_provider_auth_config_equality() {
        let secret1 = IdentityProviderConfig::SharedSecret {
            id: "test-id".to_string(),
            data: "secret0".to_string(),
        };
        let secret2 = IdentityProviderConfig::SharedSecret {
            id: "test-id".to_string(),
            data: "secret0".to_string(),
        };
        let secret3 = IdentityProviderConfig::SharedSecret {
            id: "test-id".to_string(),
            data: "secret2".to_string(),
        };

        assert_eq!(secret1, secret2);
        assert_ne!(secret1, secret3);
    }

    #[test]
    fn test_token_verifier_auth_config_equality() {
        let secret1 = IdentityVerifierConfig::SharedSecret {
            id: "test-id".to_string(),
            data: "secret0".to_string(),
        };
        let secret2 = IdentityVerifierConfig::SharedSecret {
            id: "test-id".to_string(),
            data: "secret0".to_string(),
        };
        let secret3 = IdentityVerifierConfig::SharedSecret {
            id: "test-id".to_string(),
            data: "secret2".to_string(),
        };

        assert_eq!(secret1, secret2);
        assert_ne!(secret1, secret3);
    }

    #[test]
    fn test_config_clone() {
        let server_config = create_test_server_config();
        let client_config = create_test_client_config();
        let auth = IdentityProviderConfig::SharedSecret {
            id: "test-provider".to_string(),
            data: "secret0".to_string(),
        };

        let config1 = Config::new()
            .with_servers(vec![server_config])
            .with_clients(vec![client_config])
            .with_token_provider_auth(auth);

        let config2 = config1.clone();

        assert_eq!(config1.servers, config2.servers);
        assert_eq!(config1.clients, config2.clients);
        assert_eq!(config1.token_provider, config2.token_provider);
        assert_eq!(config1.token_verifier, config2.token_verifier);
    }

    #[tokio::test]
    async fn test_config_into_service() {
        let server_config = create_test_server_config();
        let client_config = create_test_client_config();
        let auth = IdentityProviderConfig::SharedSecret {
            id: "test-provider".to_string(),
            data: TEST_VALID_SECRET.to_string(),
        };

        let config = Config::new()
            .with_servers(vec![server_config.clone()])
            .with_clients(vec![client_config])
            .with_token_provider_auth(auth);

        let id = ID::new_with_name(Kind::new("slim").unwrap(), "test-instance").unwrap();
        let group_name = Some("test-group".to_string());
        let message_processor = Arc::new(MessageProcessor::new());

        let _control_plane =
            config.into_service(id, group_name, message_processor, &[server_config]);
    }

    #[test]
    fn test_config_debug_trait() {
        let config = Config::new();
        let debug_str = format!("{:?}", config);
        assert!(debug_str.contains("Config"));
        assert!(debug_str.contains("servers"));
        assert!(debug_str.contains("clients"));
    }

    mod serde_tests {
        use super::*;
        use serde_json;

        #[test]
        fn test_token_provider_auth_config_serialize_shared_secret() {
            let auth = IdentityProviderConfig::SharedSecret {
                id: "test-provider".to_string(),
                data: "test-secret".to_string(),
            };
            let json = serde_json::to_string(&auth).unwrap();
            assert!(json.contains("shared_secret"));
            assert!(json.contains("test-secret"));
        }

        #[test]
        fn test_token_provider_auth_config_deserialize_shared_secret() {
            let json = r#"{"type": "shared_secret", "id": "test-provider", "data": "test-secret"}"#;
            let auth: IdentityProviderConfig = serde_json::from_str(json).unwrap();

            match auth {
                IdentityProviderConfig::SharedSecret { id, data } => {
                    assert_eq!(id, "test-provider");
                    assert_eq!(data, "test-secret");
                }
                _ => panic!("Expected SharedSecret variant"),
            }
        }

        #[test]
        fn test_config_validate_with_multiple_servers() {
            let server1 = create_test_server_config();
            let server2 = ServerConfig::with_endpoint("127.0.0.1:50052")
                .with_tls_settings(slim_config::tls::server::TlsServerConfig::insecure());

            let config = Config::new().with_servers(vec![server1, server2]);
            assert!(config.validate().is_ok());
        }

        #[test]
        fn test_config_validate_with_multiple_clients() {
            let client1 = create_test_client_config();
            let client2 = ClientConfig::with_endpoint("http://127.0.0.1:50052")
                .with_tls_setting(slim_config::tls::client::TlsClientConfig::insecure());

            let config = Config::new().with_clients(vec![client1, client2]);
            assert!(config.validate().is_ok());
        }

        #[test]
        fn test_config_with_all_auth_combinations() {
            let provider_auth = IdentityProviderConfig::SharedSecret {
                id: "test-provider".to_string(),
                data: "provider-secret".to_string(),
            };
            let verifier_auth = IdentityVerifierConfig::SharedSecret {
                id: "test-verifier".to_string(),
                data: "verifier-secret".to_string(),
            };

            let config = Config::new()
                .with_token_provider_auth(provider_auth.clone())
                .with_token_verifier_auth(verifier_auth.clone());

            assert_eq!(config.token_provider, provider_auth);
            assert_eq!(config.token_verifier, verifier_auth);
        }

        #[test]
        fn test_empty_servers_slice() {
            let config = Config::new();
            let servers = config.servers();
            assert!(servers.is_empty());
            assert_eq!(servers.len(), 0);
        }

        #[test]
        fn test_empty_clients_slice() {
            let config = Config::new();
            let clients = config.clients();
            assert!(clients.is_empty());
            assert_eq!(clients.len(), 0);
        }

        #[test]
        fn test_config_partial_eq() {
            let config1 = Config::new();
            let config2 = Config::new();

            // Default configs should be equal
            assert_eq!(config1, config2);

            // Add server to one config
            let server_config = create_test_server_config();
            let config3 = config1.clone().with_servers(vec![server_config]);

            // Should not be equal anymore
            assert_ne!(config1, config3);
        }

        #[test]
        fn test_mixed_auth_types() {
            use slim_auth::jwt::{Algorithm, Key, KeyData, KeyFormat};

            let static_jwt =
                IdentityProviderConfig::StaticJwt(StaticJwtConfig::with_file("test-token.jwt"));

            let jwt = IdentityVerifierConfig::Jwt(JwtConfig::new(
                slim_config::auth::jwt::Claims::default(),
                std::time::Duration::from_secs(3600),
                slim_config::auth::jwt::JwtKey::Decoding(Key {
                    algorithm: Algorithm::HS256,
                    format: KeyFormat::Pem,
                    key: KeyData::Data("test-key".to_string()),
                }),
            ));

            let config = Config::new()
                .with_token_provider_auth(static_jwt.clone())
                .with_token_verifier_auth(jwt.clone());

            assert_eq!(config.token_provider, static_jwt);
            assert_eq!(config.token_verifier, jwt);
        }

        mod edge_case_tests {
            use super::*;

            #[test]
            fn test_config_builder_pattern_reuse() {
                let base_config = Config::new();

                let config1 = base_config
                    .clone()
                    .with_servers(vec![create_test_server_config()]);
                let config2 = base_config
                    .clone()
                    .with_clients(vec![create_test_client_config()]);

                // Base config should still be empty
                assert!(base_config.servers.is_empty());
                assert!(base_config.clients.is_empty());

                // Derived configs should have their respective additions
                assert_eq!(config1.servers.len(), 1);
                assert!(config1.clients.is_empty());

                assert!(config2.servers.is_empty());
                assert_eq!(config2.clients.len(), 1);
            }

            #[test]
            fn test_config_overwrite_behavior() {
                let server1 = create_test_server_config();
                let server2 = ServerConfig::with_endpoint("127.0.0.1:50052")
                    .with_tls_settings(slim_config::tls::server::TlsServerConfig::insecure());

                let config = Config::new()
                    .with_servers(vec![server1])
                    .with_servers(vec![server2.clone()]); // This should overwrite, not append

                assert_eq!(config.servers.len(), 1);
                assert_eq!(config.servers[0], server2);
            }

            #[test]
            fn test_auth_config_none_variants() {
                let config = Config::new();

                assert_eq!(config.token_provider, IdentityProviderConfig::None);
                assert_eq!(config.token_verifier, IdentityVerifierConfig::None);

                // Adding one shouldn't affect the other
                let config_with_provider =
                    config
                        .clone()
                        .with_token_provider_auth(IdentityProviderConfig::SharedSecret {
                            id: "test-provider".to_string(),
                            data: "secret".to_string(),
                        });

                assert_ne!(
                    config_with_provider.token_provider,
                    IdentityProviderConfig::None
                );
                assert_eq!(
                    config_with_provider.token_verifier,
                    IdentityVerifierConfig::None
                );
            }
        }

        #[test]
        fn test_token_verifier_auth_config_serialize_shared_secret() {
            let auth = IdentityVerifierConfig::SharedSecret {
                id: "test-verifier".to_string(),
                data: "test-secret".to_string(),
            };
            let json = serde_json::to_string(&auth).unwrap();
            assert!(json.contains("shared_secret"));
            assert!(json.contains("test-secret"));
        }

        #[test]
        fn test_token_verifier_auth_config_deserialize_shared_secret() {
            let json = r#"{"type": "shared_secret", "id": "test-verifier", "data": "test-secret"}"#;
            let auth: IdentityVerifierConfig = serde_json::from_str(json).unwrap();

            match auth {
                IdentityVerifierConfig::SharedSecret { id, data } => {
                    assert_eq!(id, "test-verifier");
                    assert_eq!(data, "test-secret");
                }
                _ => panic!("Expected SharedSecret variant"),
            }
        }
    }
}