netviper-talos 0.2.4

A Rust-based secure licensing system.
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
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
//! Core license client for Talos.
//!
//! This module provides the main `License` struct for interacting with the
//! Talos license server. It supports both online and offline (air-gapped)
//! validation modes.
//!
//! ## Basic Usage (Online)
//!
//! ```rust,ignore
//! use talos::client::license::License;
//! use talos::errors::LicenseResult;
//!
//! #[tokio::main]
//! async fn main() -> LicenseResult<()> {
//!     // Create a new license client
//!     let mut license = License::new(
//!         "LIC-XXXX-XXXX-XXXX".to_string(),
//!         "https://license.example.com".to_string(),
//!     );
//!
//!     // Bind to this hardware
//!     let bind_result = license.bind(Some("My Workstation"), None).await?;
//!     println!("Features: {:?}", bind_result.features);
//!
//!     // Validate the license
//!     let validation = license.validate().await?;
//!     if validation.has_feature("feature_a") {
//!         println!("Feature A is enabled!");
//!     }
//!
//!     // Send heartbeat
//!     license.heartbeat().await?;
//!
//!     // Release when done
//!     license.release().await?;
//!
//!     Ok(())
//! }
//! ```
//!
//! ## Air-Gapped Usage (Offline)
//!
//! ```rust,ignore
//! use talos::client::license::License;
//!
//! async fn check_license() -> Result<bool, Box<dyn std::error::Error>> {
//!     let mut license = License::load_from_disk().await?;
//!
//!     // Try online first, fall back to cached validation
//!     match license.validate_with_fallback().await {
//!         Ok(result) => {
//!             if let Some(warning) = &result.warning {
//!                 eprintln!("Warning: {}", warning);
//!             }
//!             Ok(true)
//!         }
//!         Err(e) => {
//!             eprintln!("License validation failed: {}", e);
//!             Ok(false)
//!         }
//!     }
//! }
//! ```

use crate::client::cache::{
    clear_cache_from_disk, load_cache_from_disk, save_cache_to_disk, CachedValidation,
};
use crate::client::encrypted_storage::{
    clear_license_from_disk, load_license_from_disk, save_license_to_disk,
};
use crate::client::errors::{ClientApiError, ClientErrorCode, ServerErrorResponse};
use crate::client::responses::{
    BindResult, FeatureResult, HeartbeatResult, ServerBindResponse, ServerFeatureResponse,
    ServerHeartbeatResponse, ServerReleaseResponse, ServerValidateResponse, ValidationResult,
};
use crate::errors::{LicenseError, LicenseResult};
use crate::hardware::get_hardware_id;

use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::time::Duration;

/// HTTP client timeout for license server requests.
const REQUEST_TIMEOUT_SECS: u64 = 30;

/// Core license representation.
///
/// This struct holds the credentials needed to interact with the license server
/// and optionally cached validation state for offline use.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct License {
    /// Human-readable license key (e.g., "LIC-XXXX-XXXX-XXXX")
    pub license_key: String,

    /// Base URL of the licensing server
    pub server_url: String,

    /// Hardware ID this license is bound to (set after bind)
    #[serde(default)]
    pub hardware_id: String,

    /// Cached validation state for offline use
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cached: Option<CachedValidation>,

    // === Legacy fields for backwards compatibility ===
    // These are kept for deserializing old license files
    /// Legacy: Server-side license identifier (UUID)
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub license_id: String,

    /// Legacy: Alias for hardware_id
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub client_id: String,

    /// Legacy: Expiry date string
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub expiry_date: String,

    /// Legacy: Features list
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub features: Vec<String>,

    /// Legacy: Server signature
    #[serde(default, skip_serializing_if = "String::is_empty")]
    pub signature: String,

    /// Legacy: Active flag
    #[serde(default)]
    pub is_active: bool,
}

// === Request Types ===

#[derive(Debug, Serialize)]
struct BindRequest {
    license_key: String,
    hardware_id: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    device_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    device_info: Option<String>,
}

#[derive(Debug, Serialize)]
struct ReleaseRequest {
    license_key: String,
    hardware_id: String,
}

#[derive(Debug, Serialize)]
struct ValidateRequest {
    license_key: String,
    hardware_id: String,
}

#[derive(Debug, Serialize)]
struct HeartbeatRequest {
    license_key: String,
    hardware_id: String,
}

#[derive(Debug, Serialize)]
struct FeatureRequest {
    license_key: String,
    hardware_id: String,
    feature: String,
}

// === Legacy Request Types ===

#[derive(Debug, Serialize)]
struct LegacyLicenseRequest {
    license_id: String,
    client_id: String,
}

#[derive(Debug, Deserialize)]
struct LegacyLicenseResponse {
    success: bool,
}

impl License {
    /// Create a new license client.
    ///
    /// The license is not bound to any hardware until `bind()` is called.
    pub fn new(license_key: String, server_url: String) -> Self {
        Self {
            license_key,
            server_url,
            hardware_id: String::new(),
            cached: None,
            // Legacy fields
            license_id: String::new(),
            client_id: String::new(),
            expiry_date: String::new(),
            features: Vec::new(),
            signature: String::new(),
            is_active: false,
        }
    }

    /// Create an HTTP client with standard timeout.
    fn http_client() -> Client {
        Client::builder()
            .timeout(Duration::from_secs(REQUEST_TIMEOUT_SECS))
            .build()
            .unwrap_or_else(|_| Client::new())
    }

    /// Parse an error response from the server.
    async fn parse_error_response(resp: reqwest::Response) -> LicenseError {
        let status = resp.status();

        // Try to parse as structured error
        match resp.json::<ServerErrorResponse>().await {
            Ok(err_resp) => LicenseError::ClientApiError(err_resp.into()),
            Err(_) => LicenseError::ServerError(format!("Request failed with status {}", status)),
        }
    }

    // =========================================================================
    // New API Methods (v1)
    // =========================================================================

    /// Bind this license to the current hardware.
    ///
    /// This registers the license key with the server and associates it with
    /// this device's hardware fingerprint.
    ///
    /// # Arguments
    ///
    /// * `device_name` - Optional human-readable name for this device
    /// * `device_info` - Optional device information (OS, version, etc.)
    ///
    /// # Returns
    ///
    /// On success, returns `BindResult` with license details including features
    /// and tier information.
    pub async fn bind(
        &mut self,
        device_name: Option<&str>,
        device_info: Option<&str>,
    ) -> LicenseResult<BindResult> {
        let hardware_id = get_hardware_id();

        let request = BindRequest {
            license_key: self.license_key.clone(),
            hardware_id: hardware_id.clone(),
            device_name: device_name.map(|s| s.to_string()),
            device_info: device_info.map(|s| s.to_string()),
        };

        let resp = Self::http_client()
            .post(format!("{}/api/v1/client/bind", self.server_url))
            .json(&request)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(Self::parse_error_response(resp).await);
        }

        let server_resp: ServerBindResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse bind response: {e}"))
        })?;

        // Update local state
        self.hardware_id = hardware_id.clone();
        self.is_active = true;

        // Update legacy fields for backwards compatibility
        self.license_id = server_resp.license_id.clone();
        self.client_id = hardware_id.clone();
        self.features = server_resp.features.clone();
        self.expiry_date = server_resp.expires_at.clone().unwrap_or_default();

        // Save to disk
        self.save_to_disk().await?;

        Ok(server_resp.into())
    }

    /// Release this license from the current hardware.
    ///
    /// This unbinds the license from this device, allowing it to be bound
    /// to a different device.
    pub async fn release(&mut self) -> LicenseResult<()> {
        if self.hardware_id.is_empty() {
            return Err(LicenseError::InvalidLicense(
                "License is not bound to any hardware.".to_string(),
            ));
        }

        let request = ReleaseRequest {
            license_key: self.license_key.clone(),
            hardware_id: self.hardware_id.clone(),
        };

        let resp = Self::http_client()
            .post(format!("{}/api/v1/client/release", self.server_url))
            .json(&request)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(Self::parse_error_response(resp).await);
        }

        let _: ServerReleaseResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse release response: {e}"))
        })?;

        // Clear local state
        self.hardware_id.clear();
        self.is_active = false;
        self.client_id.clear();
        self.cached = None;

        // Clear from disk
        clear_license_from_disk().await?;
        clear_cache_from_disk().await?;

        Ok(())
    }

    /// Validate the license online with the server.
    ///
    /// This calls the server to validate the license and updates the local
    /// cache with the response (for offline use).
    ///
    /// # Returns
    ///
    /// On success, returns `ValidationResult` with current license state.
    /// If the license has a grace period warning, it will be included.
    pub async fn validate(&mut self) -> LicenseResult<ValidationResult> {
        self.ensure_bound()?;

        let request = ValidateRequest {
            license_key: self.license_key.clone(),
            hardware_id: self.hardware_id.clone(),
        };

        let resp = Self::http_client()
            .post(format!("{}/api/v1/client/validate", self.server_url))
            .json(&request)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(Self::parse_error_response(resp).await);
        }

        let server_resp: ServerValidateResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse validate response: {e}"))
        })?;

        let result: ValidationResult = server_resp.into();

        // Update cache for offline use
        self.cached = Some(CachedValidation::new(
            self.license_key.clone(),
            self.hardware_id.clone(),
            result.features.clone(),
            result.tier.clone(),
            result.expires_at.clone(),
            result.grace_period_ends_at.clone(),
        ));

        // Save updated cache
        if let Some(ref cache) = self.cached {
            let _ = save_cache_to_disk(cache).await;
        }
        self.save_to_disk().await?;

        Ok(result)
    }

    /// Validate the license using cached state (offline mode).
    ///
    /// This checks the locally cached validation data without contacting
    /// the server. Use this for air-gapped systems during the grace period.
    ///
    /// # Returns
    ///
    /// Returns `Ok(ValidationResult)` if:
    /// - There is a valid cache for this license/hardware
    /// - The grace period has not expired
    /// - The license itself has not expired
    ///
    /// Returns `Err` if:
    /// - No cache exists
    /// - Grace period has expired (must go online)
    /// - License has expired
    pub fn validate_offline(&self) -> LicenseResult<ValidationResult> {
        // Try to get cache from memory first, then disk
        let cache = match &self.cached {
            Some(c) => c.clone(),
            None => {
                // Try loading from disk synchronously is tricky, so we'll
                // require the cache to be in memory for offline validation.
                // Users should call load_from_disk() first.
                return Err(LicenseError::InvalidLicense(
                    "No cached validation available. Call validate() while online first."
                        .to_string(),
                ));
            }
        };

        // Verify hardware binding
        if !cache.matches_hardware() {
            return Err(LicenseError::InvalidLicense(
                "Cached validation does not match current hardware.".to_string(),
            ));
        }

        // Check if license key matches
        if cache.license_key != self.license_key {
            return Err(LicenseError::InvalidLicense(
                "Cached validation is for a different license.".to_string(),
            ));
        }

        // Check if license has expired
        if cache.is_license_expired() {
            return Err(LicenseError::ClientApiError(ClientApiError::new(
                ClientErrorCode::LicenseExpired,
                "License has expired.",
            )));
        }

        // Check if grace period is still valid
        if !cache.is_valid_for_offline() {
            return Err(LicenseError::ClientApiError(
                ClientApiError::grace_period_expired(),
            ));
        }

        // Build result from cache
        let warning = cache.grace_period_ends_at.as_ref().map(|ends_at| {
            format!(
                "Offline mode - license must be validated online before {}",
                ends_at
            )
        });

        Ok(ValidationResult {
            features: cache.features.clone(),
            tier: cache.tier.clone(),
            expires_at: cache.expires_at.clone(),
            grace_period_ends_at: cache.grace_period_ends_at.clone(),
            warning,
            bandwidth_used_bytes: None,
            bandwidth_limit_bytes: None,
        })
    }

    /// Validate with automatic fallback to offline mode.
    ///
    /// This tries to validate online first. If the network request fails,
    /// it falls back to offline validation using the cached state.
    ///
    /// This is the recommended method for air-gapped systems.
    pub async fn validate_with_fallback(&mut self) -> LicenseResult<ValidationResult> {
        match self.validate().await {
            Ok(result) => Ok(result),
            Err(LicenseError::NetworkError(_)) => {
                // Network failed, try offline validation
                self.validate_offline()
            }
            Err(e) => Err(e),
        }
    }

    /// Validate a specific feature for this license.
    ///
    /// This always calls the server (authoritative check).
    pub async fn validate_feature(&self, feature: &str) -> LicenseResult<FeatureResult> {
        self.ensure_bound()?;

        let request = FeatureRequest {
            license_key: self.license_key.clone(),
            hardware_id: self.hardware_id.clone(),
            feature: feature.to_string(),
        };

        let resp = Self::http_client()
            .post(format!(
                "{}/api/v1/client/validate-feature",
                self.server_url
            ))
            .json(&request)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(Self::parse_error_response(resp).await);
        }

        let server_resp: ServerFeatureResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse feature response: {e}"))
        })?;

        Ok(server_resp.into())
    }

    /// Send a heartbeat to the server.
    ///
    /// This updates the server's `last_seen_at` timestamp for this license
    /// and refreshes the grace period for air-gapped systems.
    pub async fn heartbeat(&mut self) -> LicenseResult<HeartbeatResult> {
        self.ensure_bound()?;

        let request = HeartbeatRequest {
            license_key: self.license_key.clone(),
            hardware_id: self.hardware_id.clone(),
        };

        let resp = Self::http_client()
            .post(format!("{}/api/v1/client/heartbeat", self.server_url))
            .json(&request)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(Self::parse_error_response(resp).await);
        }

        let server_resp: ServerHeartbeatResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse heartbeat response: {e}"))
        })?;

        let result: HeartbeatResult = server_resp.into();

        // If server returned a new grace period, update cache
        if let Some(ref new_grace) = result.grace_period_ends_at {
            if let Some(ref mut cache) = self.cached {
                cache.grace_period_ends_at = Some(new_grace.clone());
                let _ = save_cache_to_disk(cache).await;
            }
        }

        Ok(result)
    }

    // =========================================================================
    // Legacy API Methods (deprecated)
    // =========================================================================

    /// Activate the license on the server.
    ///
    /// **Deprecated:** Use `bind()` instead.
    #[deprecated(since = "0.2.0", note = "Use bind() instead")]
    pub async fn activate(&mut self) -> LicenseResult<()> {
        let server_url = &self.server_url;
        let client_id = get_hardware_id();

        let payload = LegacyLicenseRequest {
            license_id: self.license_id.clone(),
            client_id: client_id.clone(),
        };

        let resp = Self::http_client()
            .post(format!("{}/activate", server_url))
            .json(&payload)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(LicenseError::ServerError(format!(
                "Activation failed with HTTP status {}",
                resp.status()
            )));
        }

        let body: LegacyLicenseResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse activation response: {e}"))
        })?;

        if !body.success {
            return Err(LicenseError::InvalidLicense(
                "Activation failed on server.".to_string(),
            ));
        }

        self.is_active = true;
        self.client_id = client_id.clone();
        self.hardware_id = client_id;

        save_license_to_disk(self).await?;

        Ok(())
    }

    /// Deactivate the license on the server.
    ///
    /// **Deprecated:** Use `release()` instead.
    #[deprecated(since = "0.2.0", note = "Use release() instead")]
    pub async fn deactivate(&mut self) -> LicenseResult<()> {
        let server_url = &self.server_url;
        let client_id = get_hardware_id();

        let payload = LegacyLicenseRequest {
            license_id: self.license_id.clone(),
            client_id,
        };

        let resp = Self::http_client()
            .post(format!("{}/deactivate", server_url))
            .json(&payload)
            .send()
            .await?;

        if !resp.status().is_success() {
            return Err(LicenseError::ServerError(format!(
                "Deactivation failed with HTTP status {}",
                resp.status()
            )));
        }

        let body: LegacyLicenseResponse = resp.json().await.map_err(|e| {
            LicenseError::ServerError(format!("Failed to parse deactivation response: {e}"))
        })?;

        if !body.success {
            return Err(LicenseError::InvalidLicense(
                "Deactivation failed on server.".to_string(),
            ));
        }

        self.is_active = false;
        clear_license_from_disk().await?;

        Ok(())
    }

    /// Send a heartbeat using the legacy API.
    ///
    /// **Deprecated:** Use `heartbeat()` instead (which returns `HeartbeatResult`).
    #[deprecated(since = "0.2.0", note = "Use heartbeat() instead")]
    pub async fn legacy_heartbeat(&self) -> LicenseResult<bool> {
        let current_hardware_id = get_hardware_id();

        if self.client_id != current_hardware_id {
            return Err(LicenseError::InvalidLicense(
                "Hardware mismatch for heartbeat.".to_string(),
            ));
        }

        // Use the old heartbeat module
        crate::client::heartbeat::send_heartbeat(self).await
    }

    // =========================================================================
    // Storage Methods
    // =========================================================================

    /// Load the license from encrypted local storage.
    pub async fn load_from_disk() -> LicenseResult<Self> {
        let mut license = load_license_from_disk().await?;

        // Also try to load cached validation
        if let Ok(cache) = load_cache_from_disk().await {
            license.cached = Some(cache);
        }

        Ok(license)
    }

    /// Save the license to encrypted local storage.
    pub async fn save_to_disk(&self) -> LicenseResult<()> {
        save_license_to_disk(self).await
    }

    /// Clear all local storage (license and cache).
    pub async fn clear_local_storage() -> LicenseResult<()> {
        clear_license_from_disk().await?;
        clear_cache_from_disk().await?;
        Ok(())
    }

    // =========================================================================
    // Helper Methods
    // =========================================================================

    /// Ensure the license is bound to hardware before making server requests.
    fn ensure_bound(&self) -> LicenseResult<()> {
        if self.hardware_id.is_empty() {
            return Err(LicenseError::InvalidLicense(
                "License is not bound. Call bind() first.".to_string(),
            ));
        }

        // Verify we're on the right hardware
        if self.hardware_id != get_hardware_id() {
            return Err(LicenseError::ClientApiError(ClientApiError::new(
                ClientErrorCode::HardwareMismatch,
                "License is bound to different hardware.",
            )));
        }

        Ok(())
    }

    /// Check if the license is currently bound to hardware.
    pub fn is_bound(&self) -> bool {
        !self.hardware_id.is_empty()
    }

    /// Get the license key.
    pub fn key(&self) -> &str {
        &self.license_key
    }

    /// Get the server URL.
    pub fn server(&self) -> &str {
        &self.server_url
    }

    /// Get the hardware ID this license is bound to.
    pub fn bound_hardware(&self) -> Option<&str> {
        if self.hardware_id.is_empty() {
            None
        } else {
            Some(&self.hardware_id)
        }
    }

    /// Get the cached validation state, if available.
    pub fn cached_validation(&self) -> Option<&CachedValidation> {
        self.cached.as_ref()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn new_license_is_unbound() {
        let license = License::new(
            "TEST-XXXX-XXXX-XXXX".to_string(),
            "http://localhost:8080".to_string(),
        );

        assert!(!license.is_bound());
        assert!(license.bound_hardware().is_none());
        assert_eq!(license.key(), "TEST-XXXX-XXXX-XXXX");
        assert_eq!(license.server(), "http://localhost:8080");
    }

    #[test]
    fn ensure_bound_fails_when_unbound() {
        let license = License::new(
            "TEST-XXXX-XXXX-XXXX".to_string(),
            "http://localhost:8080".to_string(),
        );

        let result = license.ensure_bound();
        assert!(result.is_err());
    }

    #[test]
    fn validate_offline_requires_cache() {
        let license = License::new(
            "TEST-XXXX-XXXX-XXXX".to_string(),
            "http://localhost:8080".to_string(),
        );

        let result = license.validate_offline();
        assert!(result.is_err());
    }
}