Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Polarion Changelog

## 0.3.5

- Add login with username and access token

## 0.3.3

- Add new test configuration properties for Module/Revision API test data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Xunit;
using Polarion.Tests.Helpers;
using FluentAssertions;

namespace Polarion.Tests.Integration;

public class PolarionClientLoginWithTokenTests : IAsyncLifetime
{
private readonly TestConfiguration _config;
private PolarionClient _client = null!;

public PolarionClientLoginWithTokenTests()
{
// Load configuration from the test settings file
_config = TestConfigurationLoader.Load("../../../appsettings.loginWithToken.test.json");
}

public async Task InitializeAsync()
{
// Create the client before each test
var result = await PolarionClient.CreateAsync(_config.PolarionClient);
result.IsSuccess.Should().BeTrue("Polarion client should be created successfully");
_client = result.Value;
_client.Should().NotBeNull("Polarion client should be created successfully");
}

public Task DisposeAsync()
{
return Task.CompletedTask;
}


[Fact]
public async Task GetWorkItemById_ShouldReturnValidWorkItem()
{
// Arrange
var workItemId = _config.TestScenarioData.GetWorkItemByIdAsyncWorkItemId;

// Act
var result = await _client.GetWorkItemByIdAsync(workItemId);

// Assert
result.IsSuccess.Should().BeTrue("Work item retrieval should succeed");
var workItem = result.Value;
workItem.Should().NotBeNull();
workItem.id.Should().NotBeNullOrEmpty();
workItem.title.Should().NotBeNullOrEmpty();
workItem.type.id.Should().NotBeNullOrEmpty();
workItem.status.id.Should().NotBeNullOrEmpty();
workItem.author.name.Should().NotBeNullOrEmpty();
workItem.description.content.Should().NotBeNullOrEmpty();
}
}
13 changes: 13 additions & 0 deletions src/Polarion.Tests/appsettings.loginWithToken.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"PolarionClient": {
"ServerUrl": "",
"Username": "",
"Mechanism": "AccessToken",
"Token": "",
"ProjectId": "",
"TimeoutSeconds": 60
},
"TestScenarioData": {
"GetWorkItemByIdAsyncWorkItemId": ""
}
}
10 changes: 9 additions & 1 deletion src/Polarion/Client/PolarionClient_CreateAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public static async Task<Result<PolarionClient>> CreateAsync(PolarionClientConfi
try
{
// Login using the Session service
var loginResponse = await sessionClient.logInAsync(config.Username, config.Password);
Object loginResponse;
if (config.Mechanism is not null && "AccessToken".Equals(config.Mechanism))
{
loginResponse = await sessionClient.logInWithTokenAsync(config.Mechanism, config.Username, config.Token);
}
else
{
loginResponse = await sessionClient.logInAsync(config.Username, config.Password);
}
if (loginResponse is null)
{
return Result.Fail<PolarionClient>("Login failed - invalid credentials");
Expand Down
2 changes: 1 addition & 1 deletion src/Polarion/Polarion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- Package Metadata -->
<PackageId>Polarion</PackageId>
<Version>0.3.4</Version>
<Version>0.3.5</Version>
<Authors>Todd Schavey</Authors>
<Company>Peakflames</Company>
<Description>A C# package to access the Polarion WSDL API. Complete API documentation available at: https://github.com/peakflames/PolarionApiClient/blob/main/api.md</Description>
Expand Down
8 changes: 6 additions & 2 deletions src/Polarion/PolarionClientConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ public record PolarionClientConfiguration
{
public string ServerUrl { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public string? Password { get; set; }
public string? Mechanism { get; set; }
public string? Token { get; set; }
public string ProjectId { get; set; }
public int TimeoutSeconds { get; set; } = 30;

[JsonConstructor]
public PolarionClientConfiguration(string serverUrl, string username, string password, string projectId, int timeoutSeconds = 30)
public PolarionClientConfiguration(string serverUrl, string username, string projectId, int timeoutSeconds = 30, string? password = null, string? mechanism = null, string? token = null)
{
ServerUrl = serverUrl;
Username = username;
Password = password;
Mechanism = mechanism;
Token = token;
ProjectId = projectId;
TimeoutSeconds = timeoutSeconds;
}
Expand Down