actix / actix-extras

@@ -80,8 +80,9 @@
Loading
80 80
    }
81 81
82 82
    /// Set custom cookie max-age
83 -
    pub fn cookie_max_age(mut self, max_age: Duration) -> Self {
84 -
        Rc::get_mut(&mut self.0).unwrap().max_age = Some(max_age);
83 +
    /// Use `None` for session-only cookies
84 +
    pub fn cookie_max_age(mut self, max_age: impl Into<Option<Duration>>) -> Self {
85 +
        Rc::get_mut(&mut self.0).unwrap().max_age = max_age.into();
85 86
        self
86 87
    }
87 88
@@ -450,6 +451,7 @@
Loading
450 451
        // Step 1:  GET index
451 452
        //   - set-cookie actix-session will be in response (session cookie #1)
452 453
        //   - response should be: {"counter": 0, "user_id": None}
454 +
        //   - cookie should have default max-age of 7 days
453 455
        // Step 2:  GET index, including session cookie #1 in request
454 456
        //   - set-cookie will *not* be in response
455 457
        //   - response should be: {"counter": 0, "user_id": None}
@@ -510,6 +512,7 @@
Loading
510 512
                counter: 0
511 513
            }
512 514
        );
515 +
        assert_eq!(cookie_1.max_age(), Some(Duration::days(7)));
513 516
514 517
        // Step 2:  GET index, including session cookie #1 in request
515 518
        //   - set-cookie will *not* be in response
@@ -667,4 +670,33 @@
Loading
667 670
            .unwrap();
668 671
        assert_ne!(cookie_5.value(), cookie_2.value());
669 672
    }
673 +
674 +
    #[actix_rt::test]
675 +
    async fn test_max_age_session_only() {
676 +
        //
677 +
        // Test that removing max_age results in a session-only cookie
678 +
        //
679 +
        let srv = test::start(|| {
680 +
            App::new()
681 +
                .wrap(
682 +
                    RedisSession::new("127.0.0.1:6379", &[0; 32])
683 +
                        .cookie_name("test-session")
684 +
                        .cookie_max_age(None),
685 +
                )
686 +
                .wrap(middleware::Logger::default())
687 +
                .service(resource("/").route(get().to(index)))
688 +
        });
689 +
690 +
        let req = srv.get("/").send();
691 +
        let resp = req.await.unwrap();
692 +
        let cookie = resp
693 +
            .cookies()
694 +
            .unwrap()
695 +
            .clone()
696 +
            .into_iter()
697 +
            .find(|c| c.name() == "test-session")
698 +
            .unwrap();
699 +
700 +
        assert_eq!(cookie.max_age(), None);
701 +
    }
670 702
}

@@ -115,7 +115,7 @@
Loading
115 115
        let encoded = base64::encode(&credentials);
116 116
        let mut value = BytesMut::with_capacity(6 + encoded.len());
117 117
        value.put(&b"Basic "[..]);
118 -
        value.put(&encoded.as_bytes()[..]);
118 +
        value.put(encoded.as_bytes());
119 119
120 120
        HeaderValue::from_maybe_shared(value.freeze())
121 121
    }
Files Coverage
actix-cors 90.26%
actix-redis 85.01%
actix-session/src 89.07%
actix-web-httpauth/src 61.01%
actix-identity/src/lib.rs 95.96%
actix-protobuf/src/lib.rs 48.62%
Project Totals (29 files) 82.08%
1
comment: false
2

3
ignore: # ignore codecoverage on following paths
4
  - "**/examples"
5
  - ".github"
6
  - "**/*.md"
7
  - "**/*.toml"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading