[Bps-public-commit] rt-authen-externalauth branch, multiple-emails, updated. 0.10_01-69-g97a5766

Jim Brandt jbrandt at bestpractical.com
Wed Jun 27 15:49:22 EDT 2012


The branch, multiple-emails has been updated
       via  97a5766855f92111f1d30feac48b3ffe44df2e38 (commit)
       via  aba3e5956167fee376c34fad752d776742cbaeaf (commit)
       via  9f31dfaf847ea986b4f5fdeb671cf04cecdd9bcd (commit)
       via  f17c679ccb5f6bc0ca486edec3ae0f3a0c2c601e (commit)
       via  af29a308d8c59f81882bf254d7fea19b46030982 (commit)
      from  b3d3ca4285d32a8e29771d81980bb2ac5806472e (commit)

Summary of changes:
 lib/RT/Authen/ExternalAuth.pm      |   12 ++++++---
 lib/RT/Authen/ExternalAuth/LDAP.pm |    8 +++---
 lib/RT/Authen/ExternalAuth/Test.pm |   31 +++++++++++++++++++++++
 xt/ldap/multiple-emails.t          |   48 ++++++++++++++++++++++++++++++++++--
 4 files changed, 90 insertions(+), 9 deletions(-)

- Log -----------------------------------------------------------------
commit af29a308d8c59f81882bf254d7fea19b46030982
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jun 27 15:07:21 2012 -0400

    Handle undefined attr_prefix config option

diff --git a/lib/RT/Authen/ExternalAuth/LDAP.pm b/lib/RT/Authen/ExternalAuth/LDAP.pm
index c0b6651..be9a13b 100644
--- a/lib/RT/Authen/ExternalAuth/LDAP.pm
+++ b/lib/RT/Authen/ExternalAuth/LDAP.pm
@@ -135,11 +135,11 @@ sub CanonicalizeUserInfo {
     # Load the config
     my $config = $RT::ExternalSettings->{$service};
 
+    my %config_prefix;
+    %config_prefix = %{$config->{'attr_prefix'}} if defined $config->{'attr_prefix'};
+
     # Default smtp: as the most common case
-    my %filter_prefix = (
-                        proxyAddresses => [ 'smtp:'],
-                        %{$config->{'attr_prefix'}}
-                        );
+    my %filter_prefix = ( proxyAddresses => [ 'smtp:'], %config_prefix );
 
     # Build the LDAP filters
     my @filter_list;

commit f17c679ccb5f6bc0ca486edec3ae0f3a0c2c601e
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jun 27 15:11:23 2012 -0400

    Add smtp option to add_ldap_user_simple
    
    Add an optional flag to add_ldap_user_simple to create
    AD-like smtp: entries in the test LDAP server.
    
    Also doc the subroutine.

diff --git a/lib/RT/Authen/ExternalAuth/Test.pm b/lib/RT/Authen/ExternalAuth/Test.pm
index 9226a9d..fcd0f4d 100644
--- a/lib/RT/Authen/ExternalAuth/Test.pm
+++ b/lib/RT/Authen/ExternalAuth/Test.pm
@@ -131,6 +131,26 @@ sub add_ldap_user {
     return $ldap{'client'}->add( $dn, attr => [%args] );
 }
 
+=head1 add_ldap_user_simple
+
+Create a test username and add a test user to the test LDAP directory
+for testing. Accepts a hash of ldap entries and values.
+
+The %name placeholder in test email addresses is replaced
+with the generated test username before the LDAP entries are added
+to the test server.
+
+Pass add_proxy_addresses => 'test.com' to have proxyAddresses entries created to
+simulate AD. This option will add the following:
+
+    proxyAddresses smtp:testuser1 at test.com
+    proxyAddresses smtp:estuser1 at test.com
+    proxyAddresses SMTP:testuser1 at test.com
+
+Returns the test username generated.
+
+=cut
+
 { my $i = 0;
 sub add_ldap_user_simple {
     my $self = shift;
@@ -140,6 +160,17 @@ sub add_ldap_user_simple {
 
     s/\%name\b/$name/g foreach grep defined, values %args;
 
+    # The goal is to make these entries look like 'typical' AD
+    if( exists $args{add_proxy_addresses} && $args{add_proxy_addresses} ){
+        $args{proxyAddresses} = [
+           'smtp:' . $name . '@' . $args{add_proxy_addresses},
+           'smtp:' . substr($name,1) . '@' . $args{add_proxy_addresses},
+           'SMTP:' . $name . '@' . $args{add_proxy_addresses},
+       ];
+    }
+
+    delete $args{add_proxy_addresses}; # Don't want this in the LDAP entry
+
     $self->add_ldap_user(
         cn    => $name,
         mail  => "$name\@invalid.tld",

commit 9f31dfaf847ea986b4f5fdeb671cf04cecdd9bcd
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jun 27 15:14:17 2012 -0400

    Add tests for pre-existing user
    
    Add a block of tests to simulate emailing from an alternate
    address for a pre-existing user account.

diff --git a/xt/ldap/multiple-emails.t b/xt/ldap/multiple-emails.t
index 495f6e8..d8cd778 100644
--- a/xt/ldap/multiple-emails.t
+++ b/xt/ldap/multiple-emails.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Authen::ExternalAuth::Test ldap => 1, tests => 50;
+use RT::Authen::ExternalAuth::Test ldap => 1, tests => 59;
 my $class = 'RT::Authen::ExternalAuth::Test';
 
 my ($server, $client) = $class->bootstrap_ldap_basics;
@@ -16,7 +16,7 @@ RT->Config->Get('ExternalSettings')->{'My_LDAP'}{'attr_map'}{'EmailAddress'}
     = ['mail', 'alias', 'proxyAddresses', 'foo'];
 
 RT->Config->Get('ExternalSettings')->{'My_LDAP'}{'attr_prefix'}{'proxyAddresses'}
-    = [ 'smtp:', 'SMTP:', 'X400:', '' ];
+    = [ 'SMTP:', 'X400:', '' ];
 
 RT::Test->set_rights(
     { Principal => 'Everyone', Right => [qw(SeeQueue ShowTicket CreateTicket)] },
@@ -187,6 +187,50 @@ MAIL
     }
 }
 
+
+{
+    my $username = new_user();
+    my $create_user = RT::User->new(RT->SystemUser);
+    my ($id, $msg) = $create_user->Create(
+        Name => $username,
+        EmailAddress => "$username\@invalid.tld",
+        RealName => 'Test User',
+        Gecos => $username );
+    ok ($id, "Created user $username, with id $id. " . $msg );
+
+    diag "Create ticket from email with existing user.";
+    my $smtp = substr($username, 1);
+    {
+        my $mail = << "MAIL";
+Subject: Test
+From: $smtp\@alternative.tld
+
+test
+MAIL
+
+        my ($status, $id) = RT::Test->send_via_mailgate($mail);
+        is ($status >> 8, 0, "The mail gateway exited normally");
+        ok ($id, "got id of a newly created ticket - $id");
+
+        my $ticket = RT::Ticket->new( $RT::SystemUser );
+        $ticket->Load( $id );
+        ok ($ticket->id, 'loaded ticket');
+
+        my $user = $ticket->CreatorObj;
+        is( $user->id, $create_user->id );
+        is( $user->Name, $username, "Name on ticket is $username");
+        is( $user->EmailAddress, "$username\@invalid.tld" );
+
+        my $txns = $ticket->Transactions;
+        $txns->Limit( FIELD => 'Type', VALUE => 'Create' );
+        my $txn = $txns->First;
+        ok( $txn, 'Got Create transaction' );
+        my $address_ref = $txn->Addresses;
+        is( $address_ref->{From}[0]->address, "$smtp\@alternative.tld",
+            "From address set with incoming mail address.");
+    }
+}
+
 $client->unbind();
 
 sub new_user { return $class->add_ldap_user_simple( alias => '%name at alternative.tld',

commit aba3e5956167fee376c34fad752d776742cbaeaf
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jun 27 15:23:15 2012 -0400

    Documentation update for multi-value attr_map
    
    Clarify the importance of the first item in attr_map arrays.

diff --git a/lib/RT/Authen/ExternalAuth.pm b/lib/RT/Authen/ExternalAuth.pm
index f9c725d..2ddfaf0 100644
--- a/lib/RT/Authen/ExternalAuth.pm
+++ b/lib/RT/Authen/ExternalAuth.pm
@@ -154,8 +154,7 @@ external attributes, for example:
 Note that only one value is stored in RT. However, the search includes
 all external attributes if the RT field is listed in L</attr_match_list>.
 On create or update, the entered value is used as long as it's valid.
-If the user didn't enter a value then the value stored in the first external
-attribute is used. Config example:
+Below is an example configuration:
 
     attr_match_list => ['Name', 'EmailAddress'],
     attr_map => {
@@ -164,6 +163,13 @@ attribute is used. Config example:
         ...
     },
 
+If the user didn't enter a value then the value stored in the first external
+attribute is used, in the example above 'mail'. In the common case of email,
+if an email comes in from an address matched via an 'alias' entry, after the
+match the value in 'mail' will be used for EmailAddress. So when mapping
+LDAP entries to RT, make sure the first entry in the array of options to
+EmailAddress is the one you want RT to use internally as the EmailAddress.
+
 =head3 attr_prefix
 
 In some cases, multiple-value LDAP attributes may have a prefix on the values

commit 97a5766855f92111f1d30feac48b3ffe44df2e38
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Jun 27 15:44:57 2012 -0400

    Bump version to .10_02

diff --git a/lib/RT/Authen/ExternalAuth.pm b/lib/RT/Authen/ExternalAuth.pm
index 2ddfaf0..14ec94d 100644
--- a/lib/RT/Authen/ExternalAuth.pm
+++ b/lib/RT/Authen/ExternalAuth.pm
@@ -1,6 +1,6 @@
 package RT::Authen::ExternalAuth;
 
-our $VERSION = '0.10_01';
+our $VERSION = '0.10_02';
 
 =head1 NAME
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list