Skip to content

Commit 569d10b

Browse files
authored
Merge pull request #614 from mjcheetham/gitlab-fixes
Sign and ship GitLab binaries (and some minor fixes)
2 parents 0d536c4 + 202995c commit 569d10b

File tree

9 files changed

+99
-28
lines changed

9 files changed

+99
-28
lines changed

Git-Credential-Manager.sln

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,34 +405,34 @@ Global
405405
{570897DC-A85C-4598-B793-9A00CF710119}.Debug|Any CPU.Build.0 = Debug|Any CPU
406406
{570897DC-A85C-4598-B793-9A00CF710119}.MacDebug|Any CPU.ActiveCfg = Debug|Any CPU
407407
{570897DC-A85C-4598-B793-9A00CF710119}.MacDebug|Any CPU.Build.0 = Debug|Any CPU
408-
{570897DC-A85C-4598-B793-9A00CF710119}.MacRelease|Any CPU.ActiveCfg = Debug|Any CPU
409-
{570897DC-A85C-4598-B793-9A00CF710119}.MacRelease|Any CPU.Build.0 = Debug|Any CPU
410408
{570897DC-A85C-4598-B793-9A00CF710119}.Release|Any CPU.ActiveCfg = Release|Any CPU
411409
{570897DC-A85C-4598-B793-9A00CF710119}.Release|Any CPU.Build.0 = Release|Any CPU
412410
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsDebug|Any CPU.ActiveCfg = Debug|Any CPU
413411
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsDebug|Any CPU.Build.0 = Debug|Any CPU
414-
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsRelease|Any CPU.ActiveCfg = Debug|Any CPU
415-
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsRelease|Any CPU.Build.0 = Debug|Any CPU
416412
{570897DC-A85C-4598-B793-9A00CF710119}.LinuxDebug|Any CPU.ActiveCfg = Debug|Any CPU
417413
{570897DC-A85C-4598-B793-9A00CF710119}.LinuxDebug|Any CPU.Build.0 = Debug|Any CPU
418-
{570897DC-A85C-4598-B793-9A00CF710119}.LinuxRelease|Any CPU.ActiveCfg = Debug|Any CPU
419-
{570897DC-A85C-4598-B793-9A00CF710119}.LinuxRelease|Any CPU.Build.0 = Debug|Any CPU
414+
{570897DC-A85C-4598-B793-9A00CF710119}.LinuxRelease|Any CPU.ActiveCfg = Release|Any CPU
415+
{570897DC-A85C-4598-B793-9A00CF710119}.LinuxRelease|Any CPU.Build.0 = Release|Any CPU
416+
{570897DC-A85C-4598-B793-9A00CF710119}.MacRelease|Any CPU.ActiveCfg = Release|Any CPU
417+
{570897DC-A85C-4598-B793-9A00CF710119}.MacRelease|Any CPU.Build.0 = Release|Any CPU
418+
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsRelease|Any CPU.ActiveCfg = Release|Any CPU
419+
{570897DC-A85C-4598-B793-9A00CF710119}.WindowsRelease|Any CPU.Build.0 = Release|Any CPU
420420
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
421421
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.Debug|Any CPU.Build.0 = Debug|Any CPU
422422
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacDebug|Any CPU.ActiveCfg = Debug|Any CPU
423423
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacDebug|Any CPU.Build.0 = Debug|Any CPU
424-
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacRelease|Any CPU.ActiveCfg = Debug|Any CPU
425-
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacRelease|Any CPU.Build.0 = Debug|Any CPU
426424
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.Release|Any CPU.ActiveCfg = Release|Any CPU
427425
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.Release|Any CPU.Build.0 = Release|Any CPU
428426
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.WindowsDebug|Any CPU.ActiveCfg = Debug|Any CPU
429427
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.WindowsDebug|Any CPU.Build.0 = Debug|Any CPU
430-
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.WindowsRelease|Any CPU.ActiveCfg = Debug|Any CPU
431-
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.WindowsRelease|Any CPU.Build.0 = Debug|Any CPU
432428
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.LinuxDebug|Any CPU.ActiveCfg = Debug|Any CPU
433429
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.LinuxDebug|Any CPU.Build.0 = Debug|Any CPU
434-
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.LinuxRelease|Any CPU.ActiveCfg = Debug|Any CPU
435-
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.LinuxRelease|Any CPU.Build.0 = Debug|Any CPU
430+
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.LinuxRelease|Any CPU.ActiveCfg = Release|Any CPU
431+
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.LinuxRelease|Any CPU.Build.0 = Release|Any CPU
432+
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacRelease|Any CPU.ActiveCfg = Release|Any CPU
433+
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.MacRelease|Any CPU.Build.0 = Release|Any CPU
434+
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.WindowsRelease|Any CPU.ActiveCfg = Release|Any CPU
435+
{1AF9F7C5-FA2E-48F1-B216-4D5E9A27F393}.WindowsRelease|Any CPU.Build.0 = Release|Any CPU
436436
EndGlobalSection
437437
GlobalSection(SolutionProperties) = preSolution
438438
HideSolutionNode = FALSE

src/osx/SignFiles.Mac/SignFiles.Mac.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
$(OutDir)\GitHub.dll;
2828
$(OutDir)\GitHub.UI.dll;
2929
$(OutDir)\GitHub.UI.Shared.dll;
30+
$(OutDir)\GitLab.dll;
3031
$(OutDir)\Microsoft.AzureRepos.dll;
3132
$(OutDir)\gcmcore.dll;">
3233
<Authenticode>Microsoft400</Authenticode>

src/shared/GitLab.Tests/GitLabAuthenticationTests.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
42
using System.Threading.Tasks;
53
using GitCredentialManager.Tests.Objects;
6-
using Moq;
7-
using Moq.Protected;
84
using Xunit;
95

106
namespace GitLab.Tests

src/shared/GitLab.Tests/GitLabHostProviderTests.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Threading.Tasks;
43
using GitCredentialManager;
5-
using GitCredentialManager.Authentication.OAuth;
64
using GitCredentialManager.Tests.Objects;
7-
using Moq;
85
using Xunit;
96

107
namespace GitLab.Tests
@@ -28,5 +25,49 @@ public void GitLabHostProvider_IsSupported(string protocol, string host, bool ex
2825
var provider = new GitLabHostProvider(new TestCommandContext());
2926
Assert.Equal(expected, provider.IsSupported(input));
3027
}
28+
29+
[Fact]
30+
public void GitLabHostProvider_GetSupportedAuthenticationModes_DotCom_ReturnsDotComModes()
31+
{
32+
Uri targetUri = GitLabConstants.GitLabDotCom;
33+
AuthenticationModes expected = GitLabConstants.DotComAuthenticationModes;
34+
35+
var context = new TestCommandContext();
36+
var provider = new GitLabHostProvider(context);
37+
AuthenticationModes actual = provider.GetSupportedAuthenticationModes(targetUri);
38+
39+
Assert.Equal(expected, actual);
40+
}
41+
42+
[Fact]
43+
public void GitLabHostProvider_GetSupportedAuthenticationModes_Custom_NoOAuthConfig_ReturnsBasicPat()
44+
{
45+
var targetUri = new Uri("https://gitlab.example.com");
46+
var expected = AuthenticationModes.Basic
47+
| AuthenticationModes.Pat;
48+
49+
var context = new TestCommandContext();
50+
var provider = new GitLabHostProvider(context);
51+
AuthenticationModes actual = provider.GetSupportedAuthenticationModes(targetUri);
52+
53+
Assert.Equal(expected, actual);
54+
}
55+
56+
[Fact]
57+
public void GitLabHostProvider_GetSupportedAuthenticationModes_Custom_WithOAuthConfig_ReturnsBasicPatBrowser()
58+
{
59+
var targetUri = new Uri("https://gitlab.example.com");
60+
var expected = AuthenticationModes.Basic
61+
| AuthenticationModes.Pat
62+
| AuthenticationModes.Browser;
63+
64+
var context = new TestCommandContext();
65+
context.Environment.Variables[GitLabConstants.EnvironmentVariables.DevOAuthClientId] = "abcdefg1234567";
66+
67+
var provider = new GitLabHostProvider(context);
68+
AuthenticationModes actual = provider.GetSupportedAuthenticationModes(targetUri);
69+
70+
Assert.Equal(expected, actual);
71+
}
3172
}
3273
}

src/shared/GitLab/GitLabAuthentication.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Threading.Tasks;
33
using System.Collections.Generic;
4-
using System.Globalization;
54
using System.Net.Http;
65
using System.Text;
76
using System.Threading;

src/shared/GitLab/GitLabConstants.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
42

53
namespace GitLab
64
{
75
public static class GitLabConstants
86
{
7+
public static readonly Uri GitLabDotCom = new Uri("https://gitlab.com");
8+
99
// owned by https://gitlab.com/gitcredentialmanager
1010
public const string OAuthClientId = "172b9f227872b5dde33f4d9b1db06a6a5515ae79508e7a00c973c85ce490671e";
1111
public const string OAuthClientSecret = "7da92770d1447508601e4ba026bc5eb655c8268e818cd609889cc9bae2023f39";
@@ -15,7 +15,7 @@ public static class GitLabConstants
1515
public static readonly Uri OAuthAuthorizationEndpointRelativeUri = new Uri("/oauth/authorize", UriKind.Relative);
1616
public static readonly Uri OAuthTokenEndpointRelativeUri = new Uri("/oauth/token", UriKind.Relative);
1717

18-
public const AuthenticationModes DotComAuthenticationModes = AuthenticationModes.Browser | AuthenticationModes.Pat;
18+
public const AuthenticationModes DotComAuthenticationModes = AuthenticationModes.All;
1919

2020
public static class EnvironmentVariables
2121
{
@@ -37,6 +37,13 @@ public static class Credential
3737
}
3838
}
3939

40-
public static bool IsGitLabDotCom(Uri uri) => StringComparer.OrdinalIgnoreCase.Equals(uri.Host, "gitlab.com");
40+
public static class HelpUrls
41+
{
42+
public const string GitLab = "https://aka.ms/gcm/gitlab";
43+
}
44+
45+
public static bool IsGitLabDotCom(Uri uri) => StringComparer.OrdinalIgnoreCase.Equals(uri.Host, GitLabDotCom.Host);
46+
47+
public static bool IsGitLabDotComClientId(string clientId) => StringComparer.OrdinalIgnoreCase.Equals(clientId, OAuthClientId);
4148
}
4249
}

src/shared/GitLab/GitLabHostProvider.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,39 @@ internal AuthenticationModes GetSupportedAuthenticationModes(Uri targetUri)
132132
}
133133
}
134134

135+
// GitLab.com has well-known supported auth modes
135136
if (GitLabConstants.IsGitLabDotCom(targetUri))
136137
{
137-
return AuthenticationModes.All;
138+
return GitLabConstants.DotComAuthenticationModes;
138139
}
139140

140-
Context.Streams.Error.WriteLine($"Missing OAuth configuration for {targetUri.Host}, see https://github.com/GitCredentialManager/git-credential-manager/blob/main/docs/gitlab.md.");
141-
// Would like to query password_authentication_enabled_for_git, but can't unless logged in https://gitlab.com/gitlab-org/gitlab/-/issues/349463
142-
return AuthenticationModes.Basic | AuthenticationModes.Pat;
141+
// Try to detect what auth modes are available for this non-GitLab.com host.
142+
// Assume that PATs are always available to give at least one option to users!
143+
var modes = AuthenticationModes.Pat;
144+
145+
// If there is a configured OAuth client ID (that isn't GitLab.com's client ID)
146+
// then assume OAuth is possible.
147+
string oauthClientId = GitLabOAuth2Client.GetClientId(Context.Settings);
148+
if (!GitLabConstants.IsGitLabDotComClientId(oauthClientId))
149+
{
150+
modes |= AuthenticationModes.Browser;
151+
}
152+
else
153+
{
154+
// Tell the user that they may wish to configure OAuth for this GitLab instance
155+
Context.Streams.Error.WriteLine(
156+
$"warning: missing OAuth configuration for {targetUri.Host} - see {GitLabConstants.HelpUrls.GitLab} for more information");
157+
}
158+
159+
// Would like to query password_authentication_enabled_for_git, but can't unless logged in https://gitlab.com/gitlab-org/gitlab/-/issues/349463.
160+
// For now assume password auth is always available.
161+
bool supportsBasic = true;
162+
if (supportsBasic)
163+
{
164+
modes |= AuthenticationModes.Basic;
165+
}
166+
167+
return modes;
143168
}
144169

145170
// <remarks>Stores OAuth tokens as a side effect</remarks>

src/windows/Installer.Windows/Setup.iss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ Source: "{#PayloadDir}\GitHub.dll"; DestDir:
112112
Source: "{#PayloadDir}\GitHub.UI.exe"; DestDir: "{app}"; Flags: ignoreversion
113113
Source: "{#PayloadDir}\GitHub.UI.exe.config"; DestDir: "{app}"; Flags: ignoreversion
114114
Source: "{#PayloadDir}\GitHub.UI.Shared.dll"; DestDir: "{app}"; Flags: ignoreversion
115+
Source: "{#PayloadDir}\GitLab.dll"; DestDir: "{app}"; Flags: ignoreversion
115116
Source: "{#PayloadDir}\Microsoft.AzureRepos.dll"; DestDir: "{app}"; Flags: ignoreversion
116117
Source: "{#PayloadDir}\gcmcore.dll"; DestDir: "{app}"; Flags: ignoreversion
117118
Source: "{#PayloadDir}\gcmcoreui.dll"; DestDir: "{app}"; Flags: ignoreversion

src/windows/Payload.Windows/Payload.Windows.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
$(OutDir)git-credential-manager-core.exe;
2828
$(OutDir)GitHub.dll;
2929
$(OutDir)GitHub.UI.exe;
30+
$(OutDir)GitLab.dll;
3031
$(OutDir)Microsoft.AzureRepos.dll;
3132
$(OutDir)gcmcore.dll;
3233
$(OutDir)gcmcoreui.dll;

0 commit comments

Comments
 (0)