Skip to content

Commit

Permalink
Merge pull request #24 from metageek-llc/feature/Tls1.2-support
Browse files Browse the repository at this point in the history
Feature/tls1.2 support
  • Loading branch information
ashokgelal authored Jul 7, 2020
2 parents db704d0 + 9cbc411 commit 80c772f
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Magpie/Magpie.Example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("0.0.2.0")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyVersion("0.0.3.0")]
[assembly: AssemblyFileVersion("0.0.3.0")]
44 changes: 43 additions & 1 deletion src/Magpie/Magpie.Tests/Services/MagpieTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Magpie.Tests.Mocks;
using MagpieUpdater.Interfaces;
using MagpieUpdater.Models;
Expand Down Expand Up @@ -194,7 +195,7 @@ public void SwitchingChannel_FailingToEnroll_DoesNotUpdateSubscribedChannel()
}

[TestMethod]
public void SwitchingToChannelThatDoesNotRequireEnrollment_UpdatesSubscribedChannel()
public void SwitchingChannel_ChannelDoesNotRequireEnrollment_UpdatesSubscribedChannel()
{
var updateDecider = Substitute.For<UpdateDecider>(new DebuggingWindowViewModel());
updateDecider.ShouldUpdate(Arg.Any<Channel>(), true).Returns(false);
Expand All @@ -203,5 +204,46 @@ public void SwitchingToChannelThatDoesNotRequireEnrollment_UpdatesSubscribedChan

Assert.AreEqual(3, _mockMagpie.AppInfo.SubscribedChannel);
}

[TestMethod]
public async Task SwitchingChannelAsync_SuccessfullyEnrolled_ReturnsTrue()
{
var updateDecider = Substitute.For<UpdateDecider>(new DebuggingWindowViewModel());
_mockMagpie.UpdateDecider = updateDecider;
updateDecider.ShouldUpdate(Arg.Any<Channel>(), true).Returns(false);
_mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = true };
var success = await _mockMagpie.SwitchSubscribedChannelAsync(4);

Assert.IsTrue(success);
}

[TestMethod]
public async Task SwitchingAsync_ChannelDoesNotRequireEnrollment_ReturnsTrue()
{
var updateDecider = Substitute.For<UpdateDecider>(new DebuggingWindowViewModel());
updateDecider.ShouldUpdate(Arg.Any<Channel>(), true).Returns(false);
_mockMagpie.UpdateDecider = updateDecider;
var success = await _mockMagpie.SwitchSubscribedChannelAsync(3);

Assert.IsTrue(success);
}

[TestMethod]
public async Task SwitchingChannelAsync_FailingToEnroll_ReturnsFalse()
{
_mockMagpie._enrollmentToReturn = new Enrollment(new Channel()) { IsEnrolled = false };
var success = await _mockMagpie.SwitchSubscribedChannelAsync(4);

Assert.IsFalse(success);
}

[TestMethod]
public async Task SwitchingAsync_AppCastIsEmpty_ReturnsFalse()
{
_mockMagpie.RemoteContentDownloader.DownloadStringContent(Arg.Any<string>(), Arg.Any<IDebuggingInfoLogger>()).Returns(Task.FromResult(string.Empty));
var success = await _mockMagpie.SwitchSubscribedChannelAsync(3);

Assert.IsFalse(success);
}
}
}
Binary file modified src/Magpie/Magpie.latest.nupkg
Binary file not shown.
6 changes: 3 additions & 3 deletions src/Magpie/Magpie/Models/Enrollment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
public class Enrollment
{
public Channel Channel { get; private set; }
public bool IsRequired { get; internal set; }
public bool IsEnrolled { get; internal set; }
public string Email { get; internal set; }
public bool IsRequired { get; set; }
public bool IsEnrolled { get; set; }
public string Email { get; set; }

public Enrollment(Channel channel)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Magpie/Magpie/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("0.2.2.0")]
[assembly: AssemblyFileVersion("0.2.2.0")]
[assembly: AssemblyVersion("0.3.2.0")]
[assembly: AssemblyFileVersion("0.3.2.0")]
[assembly: InternalsVisibleTo("Magpie.Tests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
3 changes: 2 additions & 1 deletion src/Magpie/Magpie/Resources/Strings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<system:String x:Key="_skipVersion">Skip this Version</system:String>
<system:String x:Key="_remindMeLater">Remind Me Later</system:String>
<system:String x:Key="_dontEnroll">I don't want to</system:String>
<system:String x:Key="_enroll">I don't want to</system:String>
<system:String x:Key="_enroll">Enroll</system:String>
<system:String x:Key="_enrollMsg">Please provide your email address to join the {0} Program</system:String>
<system:String x:Key="_eulaMsg" xml:space="preserve">By enrolling in this program you agree with our </system:String>
<system:String x:Key="_eula">Terms and Condtions</system:String>
</ResourceDictionary>
2 changes: 1 addition & 1 deletion src/Magpie/Magpie/Services/AnalyticsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public virtual void LogUpdateAvailable(Channel channel)
{
}

public void LogEnrollment(Enrollment enrollment)
public virtual void LogEnrollment(Enrollment enrollment)
{
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Magpie/Magpie/Services/DefaultRemoteContentDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace MagpieUpdater.Services
{
internal class DefaultRemoteContentDownloader : IRemoteContentDownloader
{
public DefaultRemoteContentDownloader()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;
}
public async Task<string> DownloadStringContent(string url, IDebuggingInfoLogger logger = null)
{
try
Expand Down Expand Up @@ -48,4 +53,4 @@ public async Task<string> DownloadFile(string sourceUrl, string destinationPath,
}
}
}
}
}
20 changes: 15 additions & 5 deletions src/Magpie/Magpie/Services/Magpie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ await Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggi
.ConfigureAwait(false);
}

private async Task Check(string appcastUrl, CheckState checkState, int channelId = 1, bool showDebuggingWindow = false)
public Task<bool> SwitchSubscribedChannelAsync(int channelId, bool showDebuggingWindow = false)
{
return Check(AppInfo.AppCastUrl, CheckState.ChannelSwitch, channelId, showDebuggingWindow);
}

private async Task<bool> Check(string appcastUrl, CheckState checkState, int channelId = 1, bool showDebuggingWindow = false)
{
_logger.Log(string.Format("Starting fetching remote channel content from address: {0}", appcastUrl));
try
Expand All @@ -64,12 +69,15 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId
{
ShowErrorWindow();
}
return;
return false;
}

var appcast = ParseAppcast(data);

if (checkState == CheckState.ChannelSwitch && FailedToEnroll(appcast, channelId)) return;
if (checkState == CheckState.ChannelSwitch && CheckIfFailedToEnroll(appcast, channelId))
{
return false;
}

var channelToUpdateFrom = BestChannelFinder.Find(channelId, appcast.Channels);

Expand All @@ -83,18 +91,20 @@ private async Task Check(string appcastUrl, CheckState checkState, int channelId
ShowNoUpdatesWindow();
}
AppInfo.SubscribedChannel = channelId;
return true;
}
catch (Exception ex)
{
_logger.Log(string.Format("Error parsing remote channel: {0}", ex.Message));
return false;
}
finally
{
_logger.Log("Finished fetching remote channel content");
}
}

private bool FailedToEnroll(RemoteAppcast appcast, int channelId)
private bool CheckIfFailedToEnroll(RemoteAppcast appcast, int channelId)
{
var channel = appcast.Channels.FirstOrDefault(c => c.Id == channelId);
var enrollment = new Enrollment(channel);
Expand All @@ -103,7 +113,6 @@ private bool FailedToEnroll(RemoteAppcast appcast, int channelId)
enrollment.IsRequired = true;
ShowEnrollmentWindow(enrollment);
}
_analyticsLogger.LogEnrollment(enrollment);
OnEnrollmentAvailableEvent(new SingleEventArgs<Enrollment>(enrollment));
return enrollment.IsRequired && !enrollment.IsEnrolled;
}
Expand Down Expand Up @@ -266,6 +275,7 @@ protected virtual void OnArtifactDownloadedEvent(SingleEventArgs<string> args)

protected virtual void OnEnrollmentAvailableEvent(SingleEventArgs<Enrollment> args)
{
_analyticsLogger.LogEnrollment(args.Payload);
var handler = EnrollmentAvailableEvent;
if (handler != null) handler(this, args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Magpie/Magpie/Views/EnrollmentWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
Text="{DynamicResource _eulaMsg}"
TextWrapping="Wrap">
<Hyperlink NavigateUri="{Binding EnrollmentEulaUrl}" RequestNavigate="NavigateUri">
<Run Text="EULA"/>
<Run Text="{DynamicResource _eula}"/>
</Hyperlink>
</TextBlock>
<Border Grid.Row="3"
Expand Down

0 comments on commit 80c772f

Please sign in to comment.