Skip to content
Merged
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: 2 additions & 2 deletions bitwarden_license/src/Sso/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@using static Bit.Core.Utilities.AssemblyHelpers;
@inject Bitwarden.Server.Sdk.Environment.IBitwardenEnvironment BitwardenEnvironment

<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -30,7 +30,7 @@
</div>
<div class="col text-center"></div>
<div class="col text-right">
Version @GetVersion()
Version @BitwardenEnvironment.Version
</div>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/Admin/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json;
using Bit.Admin.Models;
using Bit.Core.Settings;
using Bitwarden.Server.Sdk.Environment;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
Expand All @@ -18,12 +19,14 @@ public class HomeController : Controller
private readonly GlobalSettings _globalSettings;
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger<HomeController> _logger;
private readonly IBitwardenEnvironment _bitwardenEnvironment;

public HomeController(GlobalSettings globalSettings, IHttpClientFactory httpClientFactory, ILogger<HomeController> logger)
public HomeController(GlobalSettings globalSettings, IHttpClientFactory httpClientFactory, ILogger<HomeController> logger, IBitwardenEnvironment bitwardenEnvironment)
{
_globalSettings = globalSettings;
_httpClientFactory = httpClientFactory;
_logger = logger;
_bitwardenEnvironment = bitwardenEnvironment;
}

[Authorize]
Expand All @@ -32,7 +35,7 @@ public IActionResult Index()
return View(new HomeModel
{
GlobalSettings = _globalSettings,
CurrentVersion = Core.Utilities.AssemblyHelpers.GetVersion()
CurrentVersion = _bitwardenEnvironment.Version
});
}

Expand Down
9 changes: 1 addition & 8 deletions src/Admin/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Admin.Controllers;

Expand All @@ -11,10 +10,4 @@ public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(AssemblyHelpers.GetVersion());
}
}
6 changes: 5 additions & 1 deletion src/Admin/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public void Configure(
// Gates endpoints carrying IFeatureMetadata; required in any app that
// routes requests through endpoints tagged with [RequireFeature].
app.UseFeatureFlagChecks();
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapVersionEndpoint();
});
}
}
8 changes: 6 additions & 2 deletions src/Api/Controllers/ConfigController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bit.Api.Models.Response;
using Bit.Core.Settings;
using Bitwarden.Server.Sdk.Environment;
using Bitwarden.Server.Sdk.Features;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -10,18 +11,21 @@ public class ConfigController : Controller
{
private readonly IGlobalSettings _globalSettings;
private readonly IFeatureService _featureService;
private readonly IBitwardenEnvironment _bitwardenEnvironment;

public ConfigController(
IGlobalSettings globalSettings,
IFeatureService featureService)
IFeatureService featureService,
IBitwardenEnvironment bitwardenEnvironment)
{
_globalSettings = globalSettings;
_featureService = featureService;
_bitwardenEnvironment = bitwardenEnvironment;
}

[HttpGet("")]
public ConfigResponseModel GetConfigs()
{
return new ConfigResponseModel(_featureService, _globalSettings);
return new ConfigResponseModel(_featureService, _globalSettings, _bitwardenEnvironment);
}
}
9 changes: 1 addition & 8 deletions src/Api/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Api.Controllers;

Expand All @@ -17,10 +16,4 @@ public DateTime GetNow()
{
return GetAlive();
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(AssemblyHelpers.GetVersion());
}
}
18 changes: 5 additions & 13 deletions src/Api/Models/Response/ConfigResponseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Bit.Core.Enums;
using Bit.Core.Models.Api;
using Bit.Core.Settings;
using Bit.Core.Utilities;
using Bitwarden.Server.Sdk.Environment;

namespace Bit.Api.Models.Response;

Expand All @@ -24,22 +24,14 @@ public class ConfigResponseModel : ResponseModel
public CommunicationSettings Communication { get; set; }
public ServerSettingsResponseModel Settings { get; set; }

public ConfigResponseModel() : base("config")
{
Version = AssemblyHelpers.GetVersion();
GitHash = AssemblyHelpers.GetGitHash();
Environment = new EnvironmentConfigResponseModel();
FeatureStates = new Dictionary<string, JsonValue>();
Settings = new ServerSettingsResponseModel();
}

public ConfigResponseModel(
Bitwarden.Server.Sdk.Features.IFeatureService featureService,
IGlobalSettings globalSettings
IGlobalSettings globalSettings,
IBitwardenEnvironment bitwardenEnvironment
) : base("config")
{
Version = AssemblyHelpers.GetVersion();
GitHash = AssemblyHelpers.GetGitHash();
Version = bitwardenEnvironment.Version;
GitHash = bitwardenEnvironment.GitHash;
Environment = new EnvironmentConfigResponseModel
{
CloudRegion = globalSettings.BaseServiceUri.CloudRegion,
Expand Down
1 change: 1 addition & 0 deletions src/Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public void Configure(
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapVersionEndpoint();

#if !OSS
// PAM is a commercial feature; its Minimal API endpoints are only mapped in non-OSS builds.
Expand Down
46 changes: 0 additions & 46 deletions src/Core/Utilities/AssemblyHelpers.cs

This file was deleted.

9 changes: 1 addition & 8 deletions src/Icons/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Icons.Controllers;

Expand All @@ -11,10 +10,4 @@ public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(AssemblyHelpers.GetVersion());
}
}
6 changes: 5 additions & 1 deletion src/Icons/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public void Configure(
.AllowAnyMethod().AllowAnyHeader().AllowCredentials());

app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
endpoints.MapVersionEndpoint();
});
}
}
9 changes: 1 addition & 8 deletions src/Notifications/Controllers/InfoController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace Bit.Notifications.Controllers;

Expand All @@ -11,10 +10,4 @@ public DateTime GetAlive()
{
return DateTime.UtcNow;
}

[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(AssemblyHelpers.GetVersion());
}
}
1 change: 1 addition & 0 deletions src/Notifications/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void Configure(
options.TransportMaxBufferSize = 4096;
});
endpoints.MapDefaultControllerRoute();
endpoints.MapVersionEndpoint();
});
}
}
9 changes: 5 additions & 4 deletions test/Api.IntegrationTest/Controllers/ConfigControllerTests.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Net.Http.Headers;
using Bit.Api.IntegrationTest.Factories;
using Bit.Api.IntegrationTest.Helpers;
using Bit.Api.Models.Response;
using Bit.Core.AdminConsole.Entities;
using Bit.Core.Billing.Enums;
using Xunit;

namespace Bit.Api.IntegrationTest.Controllers;

file record ConfigResponse(string Version);

public class ConfigControllerTests : IClassFixture<ApiApplicationFactory>, IAsyncLifetime
{
private readonly HttpClient _client;
Expand Down Expand Up @@ -48,7 +49,7 @@ public async Task GetConfigs_Unauthenticated()

var response = await _client.GetAsync("/config");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
var result = await response.Content.ReadFromJsonAsync<ConfigResponse>();

Assert.NotNull(result);
Assert.NotEmpty(result!.Version);
Expand All @@ -61,7 +62,7 @@ public async Task GetConfigs_Authenticated()

var response = await _client.GetAsync("/config");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
var result = await response.Content.ReadFromJsonAsync<ConfigResponse>();

Assert.NotNull(result);
Assert.NotEmpty(result!.Version);
Expand All @@ -87,7 +88,7 @@ public async Task GetConfigs_WithOrganizations(int orgCount)

var response = await _client.GetAsync("/config");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<ConfigResponseModel>();
var result = await response.Content.ReadFromJsonAsync<ConfigResponse>();

Assert.NotNull(result);
Assert.NotEmpty(result!.Version);
Expand Down
6 changes: 5 additions & 1 deletion test/Api.Test/Controllers/ConfigControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using AutoFixture.Xunit2;
using Bit.Api.Controllers;
using Bit.Core.Settings;
using Bitwarden.Server.Sdk.Environment;
using Bitwarden.Server.Sdk.Features;
using NSubstitute;
using Xunit;
Expand All @@ -13,16 +14,19 @@ public class ConfigControllerTests : IDisposable
private readonly ConfigController _sut;
private readonly GlobalSettings _globalSettings;
private readonly IFeatureService _featureService;
private readonly IBitwardenEnvironment _bitwardenEnvironment;

public ConfigControllerTests()
{
_globalSettings = new GlobalSettings();
_featureService = Substitute.For<IFeatureService>();
_featureService.GetAll().Returns(new Dictionary<string, JsonValue>());
_bitwardenEnvironment = Substitute.For<IBitwardenEnvironment>();

_sut = new ConfigController(
_globalSettings,
_featureService
_featureService,
_bitwardenEnvironment
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json.Nodes;
using Bit.Api.Models.Response;
using Bit.Core.Settings;
using Bitwarden.Server.Sdk.Environment;
using Bitwarden.Server.Sdk.Features;
using NSubstitute;
using Xunit;
Expand All @@ -21,7 +22,9 @@ public void ConfigResponseModel_SuppressOnboardingInterstitialsTrue_MapsToSettin
var featureService = Substitute.For<IFeatureService>();
featureService.GetAll().Returns(new Dictionary<string, JsonValue>());

var model = new ConfigResponseModel(featureService, globalSettings);
var bitwardenEnvironment = Substitute.For<IBitwardenEnvironment>();

var model = new ConfigResponseModel(featureService, globalSettings, bitwardenEnvironment);

Assert.True(model.Settings.SuppressOnboardingInterstitials);
}
Expand All @@ -38,7 +41,9 @@ public void ConfigResponseModel_SuppressOnboardingInterstitialsFalse_MapsToSetti
var featureService = Substitute.For<IFeatureService>();
featureService.GetAll().Returns(new Dictionary<string, JsonValue>());

var model = new ConfigResponseModel(featureService, globalSettings);
var bitwardenEnvironment = Substitute.For<IBitwardenEnvironment>();

var model = new ConfigResponseModel(featureService, globalSettings, bitwardenEnvironment);

Assert.False(model.Settings.SuppressOnboardingInterstitials);
}
Expand Down
18 changes: 0 additions & 18 deletions test/Core.Test/Utilities/AssemblyHelpersTests.cs

This file was deleted.

Loading
Loading