Skip to content

Commit

Permalink
Fixes an issue where the management agent thrown an exception when re…
Browse files Browse the repository at this point in the history
…moving an alias that doesnt exist
  • Loading branch information
ryannewington committed Jul 21, 2016
1 parent 51bb084 commit 39fd010
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Lithnet.GoogleApps.MA.Setup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Product Id="*"
Name="Lithnet GoogleApps Management Agent"
Language="1033"
Version="1.1.6027"
Version="1.1.6042"
Manufacturer="Lithnet"
UpgradeCode="3410d571b358426281edb2990ae57cae" >

Expand Down
63 changes: 63 additions & 0 deletions src/Lithnet.GoogleApps.MA.UnitTests/UserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,69 @@ public void RemoveAlias()

}

[TestMethod]
public void SilentlyRemoveNonExistentAlias()
{
string id = null;
string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
User e = new User
{
PrimaryEmail = dn,
Password = Guid.NewGuid().ToString(),
Name = new UserName
{
GivenName = "gn",
FamilyName = "sn"
}
};

e = UserRequestFactory.Add(e);
id = e.Id;

string alias1 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
string alias2 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";

UserRequestFactory.AddAlias(id, alias1);
UserRequestFactory.AddAlias(id, alias2);

CSEntryChange cs = CSEntryChange.Create();
cs.ObjectModificationType = ObjectModificationType.Update;
cs.DN = dn;
cs.ObjectType = SchemaConstants.User;
cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id));

cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("aliases", new List<ValueChange>
{
new ValueChange($"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}", ValueModificationType.Delete )
}));

try
{
CSEntryChangeResult result =
ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.User]);

if (result.ErrorCode != MAExportError.Success)
{
Assert.Fail(result.ErrorName);
}

System.Threading.Thread.Sleep(5000);

e = UserRequestFactory.Get(id);

CollectionAssert.AreEquivalent(new string[] { alias1, alias2 }, e.Aliases);

}
finally
{
if (id != null)
{
UserRequestFactory.Delete(id);
}
}

}

[TestMethod]
public void ReplaceAliases()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,22 @@ private static AttributeChange ApplyUserAliasChanges(CSEntryChange csentry, User
if (!user.PrimaryEmail.Equals(alias, StringComparison.CurrentCultureIgnoreCase))
{
Logger.WriteLine($"Removing alias {alias}", LogLevel.Debug);
UserRequestFactory.RemoveAlias(csentry.DN, alias);

try
{
UserRequestFactory.RemoveAlias(csentry.DN, alias);
}
catch (Google.GoogleApiException ex)
{
if (ex.HttpStatusCode == System.Net.HttpStatusCode.NotFound)
{
Logger.WriteLine($"Alias {alias} does not exist on object");
}
else
{
throw;
}
}
}

valueChanges.Add(ValueChange.CreateValueDelete(alias));
Expand Down

0 comments on commit 39fd010

Please sign in to comment.