Skip to content

Commit

Permalink
Allow to set access token explicitly when running UI tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
PiotrKarczmarz committed Jan 17, 2025
1 parent 4352eae commit cc781f6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Cody.Core/Infrastructure/ConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public ExtensionConfiguration GetConfiguration()
CustomConfiguration = GetCustomConfiguration()
};

if (_userSettingsService.ForceAccessTokenForUITests)
{
#pragma warning disable CS0618 // Type or member is obsolete
config.AccessToken = _userSettingsService.AccessToken;
#pragma warning restore CS0618 // Type or member is obsolete
}

return config;
}

Expand Down
1 change: 1 addition & 0 deletions src/Cody.Core/Settings/IUserSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public interface IUserSettingsService
string CustomConfiguration { get; set; }
bool AcceptNonTrustedCert { get; set; }
bool AutomaticallyTriggerCompletions { get; set; }
bool ForceAccessTokenForUITests { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Cody.Core/Settings/UserSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public string AccessToken
}
set
{
if (!ForceAccessTokenForUITests)
throw new Exception("Setting access token explicitly only allowed when running UI tests!");

var userToken = _secretStorage.AccessToken;
if (!string.Equals(value, userToken, StringComparison.InvariantCulture))
{
Expand Down Expand Up @@ -105,5 +108,7 @@ public bool AutomaticallyTriggerCompletions
}
set => Set(nameof(AutomaticallyTriggerCompletions), value.ToString());
}

public bool ForceAccessTokenForUITests { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Cody.VisualStudio.Tests/PlaywrightTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private async Task InitializeAsync()
if (accessToken != null)
{
WriteLog("Using Access Token.");
CodyPackage.UserSettingsService.ForceAccessTokenForUITests = true;
CodyPackage.UserSettingsService.AccessToken = accessToken;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Cody.VisualStudio/Services/SecretStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public string AccessToken
}
set
{
var oldAccessToken = AccessToken;
Set(AccessTokenKey, value);

if (oldAccessToken != value)
AuthorizationDetailsChanged?.Invoke(this, EventArgs.Empty);
}
}
}
Expand Down

0 comments on commit cc781f6

Please sign in to comment.