77cb03ec98
Adds 8 cmdlets for Organization and Sub-Organization CRUD (Get/New/Update/Remove for each), targeting /api/v2/organizations and /api/v1/sub-organizations. Get cmdlets default to List parameter set and switch to Single when -OrganizationId or -SubOrganizationId is supplied. New/Update/Remove honor -WhatIf/-Confirm; Remove defaults to High ConfirmImpact and supports -PassThru. No project context required. Adds Get-InfisicalSANList: emits a deduplicated SAN candidate set containing the local device name, the device name suffixed with each non-empty DNS suffix found across operational adapters and the system primary domain, every IPv4 unicast address falling within RFC 1918 or CGNAT, and the IPv4/IPv6 loopback addresses. Supports optional case-insensitive -InclusionExpression and -ExclusionExpression regex filters applied in fetch -> include -> exclude -> output order. Output is a single strongly-typed System.String[] array emitted non-enumerated so List<string>.AddRange consumes it directly. Registers 10 new endpoints, adds InfisicalOrganization/InfisicalSubOrganization models with DTOs, mappers, and clients, full MAML help for all 9 new cmdlets, mapper unit tests, EndpointRegistry inline-data coverage, and docs/DesignSpec.md sections 16.7 and 16.8. build.ps1 CmdletsToExport and Test-ModuleImports expected list now contain 51 cmdlets. README updated with Organization/Sub-Organization tables, the new Get-InfisicalSANList entry, and an end-to-end certificate request example using splatted OrderedDictionary blocks.
73 lines
3.0 KiB
C#
73 lines
3.0 KiB
C#
using System.Reflection;
|
|
using PSInfisicalAPI.Models;
|
|
using Xunit;
|
|
|
|
namespace PSInfisicalAPI.Tests
|
|
{
|
|
public class SubOrganizationMapperTests
|
|
{
|
|
private static readonly System.Type MapperType = typeof(PSInfisicalAPI.Connections.InfisicalConnection).Assembly
|
|
.GetType("PSInfisicalAPI.SubOrganizations.InfisicalSubOrganizationMapper", true);
|
|
|
|
private static readonly System.Type DtoType = typeof(PSInfisicalAPI.Connections.InfisicalConnection).Assembly
|
|
.GetType("PSInfisicalAPI.SubOrganizations.InfisicalSubOrganizationResponseDto", true);
|
|
|
|
private static InfisicalSubOrganization InvokeMap(object dto)
|
|
{
|
|
MethodInfo map = MapperType.GetMethod("Map", BindingFlags.Public | BindingFlags.Static);
|
|
return (InfisicalSubOrganization)map.Invoke(null, new[] { dto });
|
|
}
|
|
|
|
[Fact]
|
|
public void Map_Null_Dto_Returns_Null()
|
|
{
|
|
Assert.Null(InvokeMap(null));
|
|
}
|
|
|
|
[Fact]
|
|
public void Map_Populates_Core_Fields()
|
|
{
|
|
object dto = System.Activator.CreateInstance(DtoType);
|
|
DtoType.GetProperty("Id").SetValue(dto, "sub-001");
|
|
DtoType.GetProperty("Name").SetValue(dto, "Platform Engineering");
|
|
DtoType.GetProperty("Slug").SetValue(dto, "platform-eng");
|
|
DtoType.GetProperty("OrganizationId").SetValue(dto, "org-001");
|
|
DtoType.GetProperty("IsAccessible").SetValue(dto, true);
|
|
DtoType.GetProperty("CreatedAt").SetValue(dto, "2026-01-15T12:34:56Z");
|
|
DtoType.GetProperty("UpdatedAt").SetValue(dto, "2026-02-20T09:00:00Z");
|
|
|
|
InfisicalSubOrganization subOrganization = InvokeMap(dto);
|
|
|
|
Assert.Equal("sub-001", subOrganization.Id);
|
|
Assert.Equal("Platform Engineering", subOrganization.Name);
|
|
Assert.Equal("platform-eng", subOrganization.Slug);
|
|
Assert.Equal("org-001", subOrganization.OrganizationId);
|
|
Assert.True(subOrganization.IsAccessible);
|
|
Assert.NotNull(subOrganization.CreatedAtUtc);
|
|
Assert.NotNull(subOrganization.UpdatedAtUtc);
|
|
}
|
|
|
|
[Fact]
|
|
public void Map_Falls_Back_To_InternalId_And_OrgId()
|
|
{
|
|
object dto = System.Activator.CreateInstance(DtoType);
|
|
DtoType.GetProperty("InternalId").SetValue(dto, "internal-id-1");
|
|
DtoType.GetProperty("OrgId").SetValue(dto, "org-fallback");
|
|
|
|
InfisicalSubOrganization subOrganization = InvokeMap(dto);
|
|
|
|
Assert.Equal("internal-id-1", subOrganization.Id);
|
|
Assert.Equal("org-fallback", subOrganization.OrganizationId);
|
|
}
|
|
|
|
[Fact]
|
|
public void MapMany_Null_Returns_Empty()
|
|
{
|
|
MethodInfo mapMany = MapperType.GetMethod("MapMany", BindingFlags.Public | BindingFlags.Static);
|
|
InfisicalSubOrganization[] result = (InfisicalSubOrganization[])mapMany.Invoke(null, new object[] { null });
|
|
Assert.NotNull(result);
|
|
Assert.Empty(result);
|
|
}
|
|
}
|
|
}
|