|
31 | 31 | use OC\User\Manager; |
32 | 32 | use OCA\User_LDAP\Access; |
33 | 33 | use OCA\User_LDAP\Connection; |
| 34 | +use OCA\User_LDAP\Group_LDAP; |
34 | 35 | use OCA\User_LDAP\IGroupLDAP; |
35 | 36 | use OCA\User_LDAP\IUserLDAP; |
| 37 | +use OCA\User_LDAP\User_LDAP; |
36 | 38 | use OCP\EventDispatcher\IEventDispatcher; |
37 | 39 | use OCP\ICacheFactory; |
38 | 40 | use OCP\IConfig; |
@@ -697,4 +699,193 @@ public function testgetLDAPGroupMemberAssoc() { |
697 | 699 | $ldapProvider = $this->getLDAPProvider($server); |
698 | 700 | $this->assertEquals('assoc_type', $ldapProvider->getLDAPGroupMemberAssoc('existing_group')); |
699 | 701 | } |
| 702 | + |
| 703 | + public function testGetMultiValueUserAttributeUserNotFound() { |
| 704 | + $this->expectException(\Exception::class); |
| 705 | + $this->expectExceptionMessage('User id not found in LDAP'); |
| 706 | + |
| 707 | + $userBackend = $this->createMock(User_LDAP::class); |
| 708 | + $userBackend->expects(self::once()) |
| 709 | + ->method('userExists') |
| 710 | + ->with('admin') |
| 711 | + ->willReturn(false); |
| 712 | + $groupBackend = $this->createMock(Group_LDAP::class); |
| 713 | + $server = $this->getServerMock($userBackend, $groupBackend); |
| 714 | + |
| 715 | + $ldapProvider = $this->getLDAPProvider($server); |
| 716 | + $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
| 717 | + } |
| 718 | + |
| 719 | + public function testGetMultiValueUserAttributeCacheHit() { |
| 720 | + $connection = $this->createMock(Connection::class); |
| 721 | + $connection->expects(self::once()) |
| 722 | + ->method('getFromCache') |
| 723 | + ->with('admin-mailAlias') |
| 724 | + ->willReturn(['aliasA@test.local', 'aliasB@test.local']); |
| 725 | + $access = $this->createMock(Access::class); |
| 726 | + $access->expects(self::once()) |
| 727 | + ->method('getConnection') |
| 728 | + ->willReturn($connection); |
| 729 | + $userBackend = $this->createMock(User_LDAP::class); |
| 730 | + $userBackend->expects(self::once()) |
| 731 | + ->method('userExists') |
| 732 | + ->with('admin') |
| 733 | + ->willReturn(true); |
| 734 | + $userBackend->expects(self::once()) |
| 735 | + ->method('getLDAPAccess') |
| 736 | + ->willReturn($access); |
| 737 | + $groupBackend = $this->createMock(Group_LDAP::class); |
| 738 | + $server = $this->getServerMock($userBackend, $groupBackend); |
| 739 | + |
| 740 | + $ldapProvider = $this->getLDAPProvider($server); |
| 741 | + $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
| 742 | + } |
| 743 | + |
| 744 | + public function testGetMultiValueUserAttributeLdapError() { |
| 745 | + $connection = $this->createMock(Connection::class); |
| 746 | + $connection->expects(self::once()) |
| 747 | + ->method('getFromCache') |
| 748 | + ->with('admin-mailAlias') |
| 749 | + ->willReturn(null); |
| 750 | + $access = $this->createMock(Access::class); |
| 751 | + $access->expects(self::once()) |
| 752 | + ->method('getConnection') |
| 753 | + ->willReturn($connection); |
| 754 | + $access->expects(self::once()) |
| 755 | + ->method('username2dn') |
| 756 | + ->with('admin') |
| 757 | + ->willReturn('admin'); |
| 758 | + $access->expects(self::once()) |
| 759 | + ->method('readAttribute') |
| 760 | + ->with('admin', 'mailAlias') |
| 761 | + ->willReturn(false); |
| 762 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
| 763 | + ->disableOriginalConstructor() |
| 764 | + ->getMock(); |
| 765 | + $userBackend->method('userExists') |
| 766 | + ->with('admin') |
| 767 | + ->willReturn(true); |
| 768 | + $userBackend->method('getLDAPAccess') |
| 769 | + ->willReturn($access); |
| 770 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
| 771 | + ->disableOriginalConstructor() |
| 772 | + ->getMock(); |
| 773 | + $server = $this->getServerMock($userBackend, $groupBackend); |
| 774 | + |
| 775 | + $ldapProvider = $this->getLDAPProvider($server); |
| 776 | + $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
| 777 | + |
| 778 | + self::assertCount(0, $values); |
| 779 | + } |
| 780 | + |
| 781 | + public function testGetMultiValueUserAttribute() { |
| 782 | + $connection = $this->createMock(Connection::class); |
| 783 | + $connection->expects(self::once()) |
| 784 | + ->method('getFromCache') |
| 785 | + ->with('admin-mailAlias') |
| 786 | + ->willReturn(null); |
| 787 | + $access = $this->createMock(Access::class); |
| 788 | + $access->expects(self::once()) |
| 789 | + ->method('getConnection') |
| 790 | + ->willReturn($connection); |
| 791 | + $access->expects(self::once()) |
| 792 | + ->method('username2dn') |
| 793 | + ->with('admin') |
| 794 | + ->willReturn('admin'); |
| 795 | + $access->expects(self::once()) |
| 796 | + ->method('readAttribute') |
| 797 | + ->with('admin', 'mailAlias') |
| 798 | + ->willReturn(['aliasA@test.local', 'aliasB@test.local']); |
| 799 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
| 800 | + ->disableOriginalConstructor() |
| 801 | + ->getMock(); |
| 802 | + $userBackend->method('userExists') |
| 803 | + ->with('admin') |
| 804 | + ->willReturn(true); |
| 805 | + $userBackend->method('getLDAPAccess') |
| 806 | + ->willReturn($access); |
| 807 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
| 808 | + ->disableOriginalConstructor() |
| 809 | + ->getMock(); |
| 810 | + $server = $this->getServerMock($userBackend, $groupBackend); |
| 811 | + |
| 812 | + $ldapProvider = $this->getLDAPProvider($server); |
| 813 | + $values = $ldapProvider->getMultiValueUserAttribute('admin', 'mailAlias'); |
| 814 | + |
| 815 | + self::assertCount(2, $values); |
| 816 | + } |
| 817 | + |
| 818 | + public function testGetUserAttributeLdapError() { |
| 819 | + $connection = $this->createMock(Connection::class); |
| 820 | + $connection->expects(self::once()) |
| 821 | + ->method('getFromCache') |
| 822 | + ->with('admin-mailAlias') |
| 823 | + ->willReturn(null); |
| 824 | + $access = $this->createMock(Access::class); |
| 825 | + $access->expects(self::once()) |
| 826 | + ->method('getConnection') |
| 827 | + ->willReturn($connection); |
| 828 | + $access->expects(self::once()) |
| 829 | + ->method('username2dn') |
| 830 | + ->with('admin') |
| 831 | + ->willReturn('admin'); |
| 832 | + $access->expects(self::once()) |
| 833 | + ->method('readAttribute') |
| 834 | + ->with('admin', 'mailAlias') |
| 835 | + ->willReturn(false); |
| 836 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
| 837 | + ->disableOriginalConstructor() |
| 838 | + ->getMock(); |
| 839 | + $userBackend->method('userExists') |
| 840 | + ->with('admin') |
| 841 | + ->willReturn(true); |
| 842 | + $userBackend->method('getLDAPAccess') |
| 843 | + ->willReturn($access); |
| 844 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
| 845 | + ->disableOriginalConstructor() |
| 846 | + ->getMock(); |
| 847 | + $server = $this->getServerMock($userBackend, $groupBackend); |
| 848 | + |
| 849 | + $ldapProvider = $this->getLDAPProvider($server); |
| 850 | + $value = $ldapProvider->getUserAttribute('admin', 'mailAlias'); |
| 851 | + |
| 852 | + self::assertNull($value); |
| 853 | + } |
| 854 | + |
| 855 | + public function testGetUserAttribute() { |
| 856 | + $connection = $this->createMock(Connection::class); |
| 857 | + $connection->expects(self::once()) |
| 858 | + ->method('getFromCache') |
| 859 | + ->with('admin-mailAlias') |
| 860 | + ->willReturn(null); |
| 861 | + $access = $this->createMock(Access::class); |
| 862 | + $access->expects(self::once()) |
| 863 | + ->method('getConnection') |
| 864 | + ->willReturn($connection); |
| 865 | + $access->expects(self::once()) |
| 866 | + ->method('username2dn') |
| 867 | + ->with('admin') |
| 868 | + ->willReturn('admin'); |
| 869 | + $access->expects(self::once()) |
| 870 | + ->method('readAttribute') |
| 871 | + ->with('admin', 'mailAlias') |
| 872 | + ->willReturn(['aliasA@test.local', 'aliasB@test.local']); |
| 873 | + $userBackend = $this->getMockBuilder(User_LDAP::class) |
| 874 | + ->disableOriginalConstructor() |
| 875 | + ->getMock(); |
| 876 | + $userBackend->method('userExists') |
| 877 | + ->with('admin') |
| 878 | + ->willReturn(true); |
| 879 | + $userBackend->method('getLDAPAccess') |
| 880 | + ->willReturn($access); |
| 881 | + $groupBackend = $this->getMockBuilder(Group_LDAP::class) |
| 882 | + ->disableOriginalConstructor() |
| 883 | + ->getMock(); |
| 884 | + $server = $this->getServerMock($userBackend, $groupBackend); |
| 885 | + |
| 886 | + $ldapProvider = $this->getLDAPProvider($server); |
| 887 | + $value = $ldapProvider->getUserAttribute('admin', 'mailAlias'); |
| 888 | + |
| 889 | + self::assertEquals('aliasA@test.local', $value); |
| 890 | + } |
700 | 891 | } |
0 commit comments