@@ -565,11 +565,47 @@ public function testImpersonate()
565
565
$ controller = new Controller ($ request , $ this ->response );
566
566
$ registry = new ComponentRegistry ($ controller );
567
567
$ component = new AuthenticationComponent ($ registry );
568
+
568
569
$ this ->assertEquals ($ impersonator , $ controller ->getRequest ()->getSession ()->read ('Auth ' ));
569
570
$ this ->assertNull ($ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
571
+
570
572
$ component ->impersonate ($ impersonated );
571
573
$ this ->assertEquals ($ impersonated , $ controller ->getRequest ()->getSession ()->read ('Auth ' ));
572
- $ this ->assertEquals ($ identity , $ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
574
+ $ this ->assertEquals ($ impersonator , $ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
575
+
576
+ $ component ->stopImpersonating ();
577
+ $ this ->assertNull ($ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
578
+ }
579
+
580
+ /**
581
+ * test that impersonate() can handle identities with array data within them.
582
+ *
583
+ * @return void
584
+ */
585
+ public function testImpersonateDecoratorIgnored ()
586
+ {
587
+ $ impersonator = ['username ' => 'mariano ' ];
588
+ $ impersonated = new ArrayObject (['username ' => 'larry ' ]);
589
+
590
+ $ this ->request ->getSession ()->write ('Auth ' , $ impersonator );
591
+ $ this ->service ->authenticate ($ this ->request );
592
+ $ identity = new Identity ($ impersonator );
593
+ $ request = $ this ->request
594
+ ->withAttribute ('identity ' , $ identity )
595
+ ->withAttribute ('authentication ' , $ this ->service );
596
+ $ controller = new Controller ($ request , $ this ->response );
597
+ $ registry = new ComponentRegistry ($ controller );
598
+ $ component = new AuthenticationComponent ($ registry );
599
+
600
+ $ this ->assertEquals ($ impersonator , $ controller ->getRequest ()->getSession ()->read ('Auth ' ));
601
+ $ this ->assertNull ($ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
602
+
603
+ $ component ->impersonate ($ impersonated );
604
+ $ this ->assertEquals ($ impersonated , $ controller ->getRequest ()->getSession ()->read ('Auth ' ));
605
+ $ this ->assertEquals (new ArrayObject ($ impersonator ), $ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
606
+
607
+ $ component ->stopImpersonating ();
608
+ $ this ->assertNull ($ controller ->getRequest ()->getSession ()->read ('AuthImpersonate ' ));
573
609
}
574
610
575
611
/**
0 commit comments