Skip to content

Commit

Permalink
b/239875086 Warn if executable does not exist (#3)
Browse files Browse the repository at this point in the history
Check if executable exists and offer user to reset
executable path when opening dialog.
  • Loading branch information
jpassing authored Aug 19, 2022
1 parent 73a6f52 commit c1bb3f5
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Google.Solutions.WWAuth.Util;
using NUnit.Framework;
using System;
using System.IO;

namespace Google.Solutions.WWAuth.Test.Data
{
Expand Down Expand Up @@ -433,5 +434,20 @@ public void WhenNewFileCreated_ThenExecutableIsInitialized()
".exe",
configuration.Options.Executable);
}

//---------------------------------------------------------------------
// ResetExecutable.
//---------------------------------------------------------------------

[Test]
public void WhenExutableInvalid_ThenResetExecutableUpdatesPath()
{
var configuration = CredentialConfiguration.NewWorkloadIdentityConfiguration();
configuration.Options.Executable = "doesnotexist.exe";

configuration.ResetExecutable();

Assert.True(File.Exists(configuration.Options.Executable));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -522,5 +522,25 @@ public void WhenApplyingChanges_DefaultsAreReapplied()
vm.ApplyChanges(null);
StringAssert.EndsWith("/changed", vm.RelyingPartyId);
}

//---------------------------------------------------------------------
// ResetExecutable.
//---------------------------------------------------------------------

[Test]
public void WhenExecutableReset_ThenEventIsRaisedAndDirtyIsSet()
{
var vm = new AdfsConfigurationViewModel(
CredentialConfigurationFile.NewWorkloadIdentityConfigurationFile(),
new Mock<IShellAdapter>().Object,
new Mock<ICertificateStoreAdapter>().Object);

PropertyAssert.RaisesPropertyChangeNotification(
vm,
m => m.IsDirty,
() => vm.ResetExecutable());

Assert.IsTrue(vm.IsDirty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public void Validate()
this.PoolConfiguration.Validate();
}

public void ResetExecutable()
{
this.Options.Executable = Assembly.GetExecutingAssembly().Location;
}

//---------------------------------------------------------------------
// Factory methods.
//---------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions sources/Google.Solutions.WWAuth/View/AdfsConfigurationSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Google.Solutions.WWAuth.Adapters;
using Google.Solutions.WWAuth.Data;
using Google.Solutions.WWAuth.Util;
using System.IO;
using System.Windows.Forms;

namespace Google.Solutions.WWAuth.View
Expand Down Expand Up @@ -140,6 +141,22 @@ public AdfsConfigurationSheet(
this.viewModel,
m => m.IsViewCertificateMenuItemEnabled,
this.Container);

this.Load += (s, e) =>
{
if (!File.Exists(viewModel.Executable) &&
MessageBox.Show(
this,
"The credential configuration contains points to a copy of WWAuth " +
"that does not exist anymore. Do you want to update the configuration " +
"to use the current path instead?",
"Executable path",
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Warning) == DialogResult.Yes)
{
viewModel.ResetExecutable();
}
};
}

public IPropertiesSheetViewModel ViewModel => this.viewModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,18 @@ public string SigningCertificateSubject
public bool IsViewCertificateMenuItemEnabled
=> this.RequestSigningCertificate != null;

public string Executable => this.File.Configuration.Options.Executable;

//---------------------------------------------------------------------
// Actions.
//---------------------------------------------------------------------

public void ResetExecutable()
{
this.File.Configuration.ResetExecutable();
this.IsDirty = true;
}

public void ReapplyProtocolDefaults()
{
//
Expand Down

0 comments on commit c1bb3f5

Please sign in to comment.