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
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ codeunit 457 "Environment Information"
exit(EnvironmentInformationImpl.GetLinkedPowerPlatformEnvironmentId());
end;

/// <summary>
/// Gets the physical location of the application service the environment is hosted on (for example, "Canada Central"). This is only callable from Microsoft published apps.
/// </summary>
/// <returns>The application service location when running on SaaS infrastructure and the information is available; otherwise, an empty string.</returns>
procedure GetApplicationServiceLocation(): Text
var
CallerModuleInfo: ModuleInfo;
begin
NavApp.GetCallerModuleInfo(CallerModuleInfo);
exit(EnvironmentInformationImpl.GetApplicationServiceLocation(CallerModuleInfo));
end;

/// <summary>
/// Checks whether the Azure geography of the application service the environment is hosted on is within the Microsoft EU Data Boundary (EUDB). This is only callable from Microsoft published apps.
/// </summary>
/// <returns>True when the environment is hosted within the EU Data Boundary. False means either that the environment is outside the EU Data Boundary or that the information is unavailable, including when not running on SaaS infrastructure.</returns>
procedure IsApplicationServiceInEUDB(): Boolean
var
CallerModuleInfo: ModuleInfo;
begin
NavApp.GetCallerModuleInfo(CallerModuleInfo);
exit(EnvironmentInformationImpl.IsApplicationServiceInEUDB(CallerModuleInfo));
end;

/// <summary>
/// Gets the value of the specified environment setting. This is only callable from Microsoft published apps.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ codeunit 3702 "Environment Information Impl."
IsSandboxInitialized: Boolean;
DefaultSandboxEnvironmentNameTxt: Label 'Sandbox', Locked = true;
DefaultProductionEnvironmentNameTxt: Label 'Production', Locked = true;
MicrosoftPublisherOnlyErr: Label 'This procedure is only available for Microsoft published apps.';

procedure IsProduction(): Boolean
begin
Expand Down Expand Up @@ -177,13 +178,39 @@ codeunit 3702 "Environment Information Impl."
exit(NavTenantSettingsHelper.GetLinkedPowerPlatformEnvironmentId());
end;

procedure GetApplicationServiceLocation(CallerModuleInfo: ModuleInfo): Text
begin
EnsureMicrosoftPublisher(CallerModuleInfo);

if not IsSaaSInfrastructure() then
exit('');

exit(NavTenantSettingsHelper.GetAppServiceLocation());
end;

procedure IsApplicationServiceInEUDB(CallerModuleInfo: ModuleInfo): Boolean
begin
EnsureMicrosoftPublisher(CallerModuleInfo);

if not IsSaaSInfrastructure() then
exit(false);

exit(NavTenantSettingsHelper.GetAppServiceInEUDB());
end;

procedure GetEnvironmentSetting(SettingName: Text; ModuleInfo: ModuleInfo): Text
begin
if ModuleInfo.Publisher <> 'Microsoft' then
exit('');
exit(NavTenantSettingsHelper.GetEnvironmentApplicationSetting(SettingName));
end;

local procedure EnsureMicrosoftPublisher(CallerModuleInfo: ModuleInfo)
begin
if CallerModuleInfo.Publisher <> 'Microsoft' then
Error(MicrosoftPublisherOnlyErr);
end;

[InternalEvent(false)]
procedure OnBeforeGetApplicationIdentifier(var AppId: Text)
begin
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace Partner.Test.Environment;

using System.Environment;
using System.TestLibraries.Utilities;

codeunit 139023 "Environment Info Test Partner"
{
Subtype = Test;

var
Assert: Codeunit "Library Assert";
MicrosoftPublisherOnlyErr: Label 'This procedure is only available for Microsoft published apps.';

[Test]
procedure GetApplicationServiceLocationRequiresMicrosoftPublisher()
var
EnvironmentInformation: Codeunit "Environment Information";
ApplicationServiceLocation: Text;
begin
// [SCENARIO] A partner app cannot read the application service location.

// [WHEN] A partner-published app requests the application service location
asserterror ApplicationServiceLocation := EnvironmentInformation.GetApplicationServiceLocation();

// [THEN] Access is denied
Assert.ExpectedError(MicrosoftPublisherOnlyErr);
end;

[Test]
procedure IsApplicationServiceInEUDBRequiresMicrosoftPublisher()
var
EnvironmentInformation: Codeunit "Environment Information";
begin
// [SCENARIO] A partner app cannot read application service EUDB membership.

// [WHEN] A partner-published app requests EUDB membership
asserterror EnvironmentInformation.IsApplicationServiceInEUDB();

// [THEN] Access is denied
Assert.ExpectedError(MicrosoftPublisherOnlyErr);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ codeunit 135091 "Environment Information Test"
Assert.IsFalse(EnvironmentInformation.IsSaaS(), 'Testability should have dictacted a non- SaaS environment');
end;

[Test]
[Scope('OnPrem')]
procedure TestApplicationServiceLocationIsEmptyOutsideSaaSInfrastructure()
begin
// [SCENARIO] Application service location is unavailable outside SaaS infrastructure.

// [GIVEN] SaaS testability is disabled
EnvironmentInfoTestLibrary.SetTestabilitySoftwareAsAService(false);

// [WHEN] The application service location is requested
// [THEN] An empty location is returned
Assert.AreEqual('', EnvironmentInformation.GetApplicationServiceLocation(), 'Application service location should be empty outside SaaS infrastructure.');
end;

[Test]
[Scope('OnPrem')]
procedure TestApplicationServiceEUDBIsFalseOutsideSaaSInfrastructure()
begin
// [SCENARIO] EUDB membership is unavailable outside SaaS infrastructure.

// [GIVEN] SaaS testability is disabled
EnvironmentInfoTestLibrary.SetTestabilitySoftwareAsAService(false);

// [WHEN] EUDB membership is requested
// [THEN] False is returned
Assert.IsFalse(EnvironmentInformation.IsApplicationServiceInEUDB(), 'Application service EUDB membership should be false outside SaaS infrastructure.');
end;

[Test]
[Scope('OnPrem')]
procedure TestIsEarlyPreviewVersionIsSet()
Expand Down
Loading