Adds module code structure, build script, test script, and API bindings

This commit is contained in:
dmilov
2020-09-28 11:25:47 +03:00
parent fe6932a5fe
commit 64e0b52224
28 changed files with 3122 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
# PowerCLI Example module for managing vSphere SSO Admin
This module is combination of .NET binary libraries for accessin vSphere SSO Admin API and PowerShell advanced funcitons exposing cmdlet-like interface to the SSO Admin features.<br/>
<br/>
The module supports PowerShell 5.1 and PowerShell 7.0 and above.<br/>
# Using the module
The module can be used without the '/src' directory. The '/src' directory contains the source code of the module.<br/>
# Using the source code
## '/src' directory
This directory contains the .NET binaries sources code and Pester integration tests that cover both the binaries and the module advanced functions functionality.<br/>
## '/src/build.ps1' script
This is the build script of the module. It requires 'dotnet' sdk, and PowerCLI to be available on the machine which runs the script. <br/>
The script builds the binarires and publishes them to the 'net45' and 'netcoreapp2.0' directories of the module.<br/>
It has also the option to run module Pester tests. The optional parameters for VC server and credentials has to be specified in order the script to run the tests. Tests run in separate PowreShell process because PowerShell has to load the load the module binaries which are build output.<br/>
## '/src/test/RunTests.ps1' script
This script can be used to run the tests<br/>

View File

@@ -0,0 +1,47 @@
#
# Module manifest for module 'VMware.vSphere.SsoAdmin'
#
# Generated by: dmilov@vmware.com
#
# Generated on: 9/25/20
@{
# Script module or binary module file associated with this manifest
RootModule = 'VMware.vSphere.SsoAdmin.psm1'
# Version number of this module.
ModuleVersion = '1.0.0'
# ID used to uniquely identify this module
GUID = 'b3e25326-e809-4d68-a252-ca5fcaf1eb8b'
# Author of this module
Author = 'Dimitar Milov'
# Company or vendor of this module
CompanyName = 'VMware, Inc.'
# Copyright statement for this module
Copyright = 'Copyright (c) VMware, Inc. All rights reserved.'
# Description of the functionality provided by this module
Description = 'PowerShell Module for Managing VMware vSphere SSO Admin functionality.'
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @(
@{"ModuleName"="VMware.VimAutomation.Common";"ModuleVersion"="12.0.0.15939652"}
)
# Functions to export from this module
FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = @()
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*'
}

View File

@@ -0,0 +1,28 @@
#
# Script module for module 'VMware.vSphere.SsoAdmin'
#
Set-StrictMode -Version Latest
$moduleFileName = 'VMware.vSphere.SsoAdmin.psd1'
# Set up some helper variables to make it easier to work with the module
$PSModule = $ExecutionContext.SessionState.Module
$PSModuleRoot = $PSModule.ModuleBase
# Import the appropriate nested binary module based on the current PowerShell version
$subModuleRoot = $PSModuleRoot
if (($PSVersionTable.Keys -contains "PSEdition") -and ($PSVersionTable.PSEdition -ne 'Desktop')) {
$subModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'netcoreapp2.0'
}
else {
$subModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'net45'
}
$subModulePath = Join-Path -Path $subModuleRoot -ChildPath $moduleFileName
$subModule = Import-Module -Name $subModulePath -PassThru
# When the module is unloaded, remove the nested binary module that was loaded with it
$PSModule.OnRemove = {
Remove-Module -ModuleInfo $subModule
}

View File

@@ -0,0 +1,86 @@
#
# Module manifest for module 'VMware.vSphere.SsoAdmin'
#
# Generated by: dmilov@vmware.com
#
# Generated on: 9/25/20
@{
# Version number of this module.
ModuleVersion = '1.0.0'
# ID used to uniquely identify this module
GUID = 'dd2b1928-e8ee-4c3a-a364-1caec6d3bd58'
# Author of this module
Author = 'Dimitar Milov'
# Company or vendor of this module
CompanyName = 'VMware, Inc.'
# Copyright statement for this module
Copyright = 'Copyright (c) VMware, Inc. All rights reserved.'
# Description of the functionality provided by this module
Description = 'PowerShell Module for Managing VMware vSphere SSO Admin functionality.'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.1'
# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''
# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = '4.5'
# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = '4.0'
# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = ''
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @(
'VMware.vSphere.SsoAdmin.Utils.dll',
'VMware.vSphere.SsoAdmin.Client.dll',
'VMware.vSphere.LsClient.dll'
)
# Script files (.ps1) that are run in the caller's environment prior to importing this module
# ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
#FormatsToProcess = 'VMware.vSphere.SsoAdmin.Format.ps1xml'
# Modules to import as nested modules of the module specified in ModuleToProcess
#NestedModules= @()
# Functions to export from this module
FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*'
# List of all modules packaged with this module
ModuleList = @()
# List of all files packaged with this module
FileList = ''
# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''
}

View File

@@ -0,0 +1,83 @@
#
# Module manifest for module 'VMware.vSphere.SsoAdmin'
#
# Generated by: dmilov@vmware.com
#
# Generated on: 9/25/20
@{
# Version number of this module.
ModuleVersion = '1.0.0'
# ID used to uniquely identify this module
GUID = '29f1ed8b-311a-4ea1-80a6-0f3ec56e8259'
# Author of this module
Author = 'Dimitar Milov'
# Company or vendor of this module
CompanyName = 'VMware, Inc.'
# Copyright statement for this module
Copyright = 'Copyright (c) VMware, Inc. All rights reserved.'
# Description of the functionality provided by this module
Description = 'PowerShell Module for Managing VMware vSphere SSO Admin functionality.'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '6.0.1'
# Specifies the compatible PSEditions of the module.
CompatiblePSEditions = @('Core')
# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
PowerShellHostVersion = ''
# Processor architecture (None, X86, Amd64, IA64) required by this module
ProcessorArchitecture = ''
# Assemblies that must be loaded prior to importing this module
RequiredAssemblies = @(
'VMware.vSphere.SsoAdmin.Utils.dll',
'VMware.vSphere.SsoAdmin.Client.dll',
'VMware.vSphere.LsClient.dll'
)
# Script files (.ps1) that are run in the caller's environment prior to importing this module
# ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
#FormatsToProcess = 'VMware.vSphere.SsoAdmin.Format.ps1xml'
# Modules to import as nested modules of the module specified in ModuleToProcess
#NestedModules= @()
# Functions to export from this module
FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*'
# List of all modules packaged with this module
ModuleList = @()
# List of all files packaged with this module
FileList = ''
# Private data to pass to the module specified in ModuleToProcess
PrivateData = ''
}

View File

@@ -0,0 +1,3 @@
**/.vs
**/bin
**/obj

View File

@@ -0,0 +1,24 @@
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.20628.921",
"ExtendedData": {
"Uri": "https://10.23.80.205/lookupservice/wsdl/lookup.wsdl",
"Namespace": "LookupServiceReference",
"SelectedAccessLevelForGeneratedClass": "Public",
"GenerateMessageContract": false,
"ReuseTypesinReferencedAssemblies": true,
"ReuseTypesinAllReferencedAssemblies": true,
"CollectionTypeReference": {
"Item1": "System.Array",
"Item2": "System.Runtime.dll"
},
"DictionaryCollectionTypeReference": {
"Item1": "System.Collections.Generic.Dictionary`2",
"Item2": "System.Collections.dll"
},
"CheckedReferencedAssemblies": [],
"InstanceId": null,
"Name": "LookupServiceReference",
"Metadata": {}
}
}

View File

@@ -0,0 +1,129 @@
// **************************************************************************
// Copyright 2019 VMware, Inc. All rights reserved. -- VMware Confidential.
// **************************************************************************
using System;
using System.Collections;
using System.Collections.Generic;
using System.IdentityModel.Selectors;
using System.Linq;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Security;
using System.Text;
using LookupServiceReference;
namespace VMware.vSphere.LsClient
{
public class LookupServiceClient {
private const int WEB_OPERATION_TIMEOUT_SECONDS = 30;
private LsPortTypeClient _lsClient;
private static readonly ManagedObjectReference RootMoRef = new ManagedObjectReference
{
type = "LookupServiceInstance",
Value = "ServiceInstance"
};
public LookupServiceClient(string hostname, X509CertificateValidator serverCertificateValidator) {
var lsUri = $"https://{hostname}/lookupservice/sdk";
_lsClient = new LsPortTypeClient(GetBinding(), new EndpointAddress(new Uri(lsUri)));
var serverAuthentication = GetServerAuthentication(serverCertificateValidator);
if (serverAuthentication != null)
{
_lsClient
.ChannelFactory
.Credentials
.ServiceCertificate
.SslCertificateAuthentication = serverAuthentication;
}
}
#region Private Helpers
private X509ServiceCertificateAuthentication GetServerAuthentication(X509CertificateValidator serverCertificateValidator)
{
if (serverCertificateValidator != null) {
return new X509ServiceCertificateAuthentication {
CertificateValidationMode = X509CertificateValidationMode.Custom,
CustomCertificateValidator = serverCertificateValidator
};
}
// Default .NET behavior for TLS certificate validation
return null;
}
private static MessageEncodingBindingElement GetWcfEncoding()
{
return new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
}
private static HttpsTransportBindingElement GetWcfTransport(bool useSystemProxy)
{
HttpsTransportBindingElement transport = new HttpsTransportBindingElement
{
RequireClientCertificate = false
};
transport.UseDefaultWebProxy = useSystemProxy;
transport.MaxBufferSize = 2147483647;
transport.MaxReceivedMessageSize = 2147483647;
return transport;
}
private static Binding GetBinding() {
var binding = new CustomBinding(GetWcfEncoding(), GetWcfTransport(true));
var timeout = TimeSpan.FromSeconds(WEB_OPERATION_TIMEOUT_SECONDS);
binding.CloseTimeout = timeout;
binding.OpenTimeout = timeout;
binding.ReceiveTimeout = timeout;
binding.SendTimeout = timeout;
return binding;
}
#endregion
public Uri GetSsoAdminEndpointUri() {
var product = "com.vmware.cis";
var endpointType = "com.vmware.cis.cs.identity.admin";
var type = "sso:admin";
return FindServiceEndpoint(product, type, endpointType);
}
private Uri FindServiceEndpoint(string product, string type, string endpointType) {
Uri result = null;
var svcContent = _lsClient.RetrieveServiceContentAsync(RootMoRef).Result;
var filterCriteria = new LookupServiceRegistrationFilter() {
searchAllSsoDomains = true,
serviceType = new LookupServiceRegistrationServiceType {
product = product,
type = type
}
};
var lsRegInfo = _lsClient.
ListAsync(svcContent.serviceRegistration, filterCriteria)
.Result?
.returnval?
.FirstOrDefault();
if (lsRegInfo != null) {
var registrationEndpooint = lsRegInfo.
serviceEndpoints?.
Where(a => a.endpointType.type == endpointType)?.
FirstOrDefault<LookupServiceRegistrationEndpoint>();
if (registrationEndpooint != null) {
result = new Uri(registrationEndpooint.url);
}
}
return result;
}
}
}

View File

@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>VMware.vSphere.LsClient</RootNamespace>
<AssemblyName>VMware.vSphere.LsClient</AssemblyName>
<Description>vSphere Lookup Service API client.</Description>
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System.IdentityModel" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.4.0" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,37 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30503.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VMware.vSphere.SsoAdminClient", "VMware.vSphere.SsoAdminClient\VMware.vSphere.SsoAdminClient.csproj", "{BD48E0DD-4048-48FD-B0BE-560E2417A2CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VMware.vSphere.LsClient", "VMware.vSphere.LsClient\VMware.vSphere.LsClient.csproj", "{EEC4C335-3E6C-4FA5-84CD-CBADCD720F35}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VMware.vSphere.SsoAdmin.Utils", "VMware.vSphere.SsoAdmin.Utils\VMware.vSphere.SsoAdmin.Utils.csproj", "{1523743E-C01E-4D37-845F-0BB8DAF9EE7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BD48E0DD-4048-48FD-B0BE-560E2417A2CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD48E0DD-4048-48FD-B0BE-560E2417A2CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD48E0DD-4048-48FD-B0BE-560E2417A2CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD48E0DD-4048-48FD-B0BE-560E2417A2CC}.Release|Any CPU.Build.0 = Release|Any CPU
{EEC4C335-3E6C-4FA5-84CD-CBADCD720F35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EEC4C335-3E6C-4FA5-84CD-CBADCD720F35}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EEC4C335-3E6C-4FA5-84CD-CBADCD720F35}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EEC4C335-3E6C-4FA5-84CD-CBADCD720F35}.Release|Any CPU.Build.0 = Release|Any CPU
{1523743E-C01E-4D37-845F-0BB8DAF9EE7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1523743E-C01E-4D37-845F-0BB8DAF9EE7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1523743E-C01E-4D37-845F-0BB8DAF9EE7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1523743E-C01E-4D37-845F-0BB8DAF9EE7E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9A376526-4487-43FF-A527-E34AD4764F12}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,16 @@
using System;
using System.IdentityModel.Selectors;
using System.Security.Cryptography.X509Certificates;
namespace VMware.vSphere.SsoAdmin.Utils
{
public class AcceptAllX509CertificateValidator : X509CertificateValidator
{
public override void Validate(X509Certificate2 certificate) {
// Check that there is a certificate.
if (certificate == null) {
throw new ArgumentNullException(nameof(certificate));
}
}
}
}

View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>VMware.vSphere.SsoAdmin.Utils</RootNamespace>
<AssemblyName>VMware.vSphere.SsoAdmin.Utils</AssemblyName>
<Description>vSphere Lookup SsoAdmin utility types.</Description>
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System.IdentityModel" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Http" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.4.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.4.0" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,8 @@
using System;
namespace VMware.vSphere.SsoAdminClient
{
public class Class1
{
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>VMware.vSphere.SsoAdminClient</RootNamespace>
<AssemblyName>VMware.vSphere.SsoAdminClient</AssemblyName>
<Description>SSO Admin API client.</Description>
<TargetFrameworks>net45;netcoreapp2.0</TargetFrameworks>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,147 @@
#**************************************************************************
# Copyright (c) VMware, Inc. All rights reserved.
#**************************************************************************
param(
[ValidateSet("Debug", "Release")]
[string]
$Configuration = "Release",
[string]
$TestVc,
[string]
$TestVcUser,
[string]
$TestVcPassword
)
function Test-BuildToolsAreAvailable {
$dotnetSdk = Get-Command 'dotnet'
if (-not $dotnetSdk) {
throw "'dotnet' sdk is not available"
}
}
function LogInfo($message) {
$dt = (Get-Date).ToLongTimeString()
Write-Host "[$dt] INFO: $message" -ForegroundColor Green
}
function Build {
$srcRoot = Join-Path $PSScriptRoot "VMware.vSphere.SsoAdmin.Client"
Push-Location $srcRoot
dotnet build -c $Configuration
Pop-Location
}
function Publish {
param($OutputFolder)
if (Test-Path $OutputFolder) {
$netcoreLsSource = [IO.Path]::Combine(
$PSScriptRoot,
"VMware.vSphere.SsoAdmin.Client",
"VMware.vSphere.LsClient",
"bin",
$Configuration,
"netcoreapp2.0",
"VMware.vSphere.LsClient.dll")
$net45LsSource = [IO.Path]::Combine(
$PSScriptRoot,
"VMware.vSphere.SsoAdmin.Client",
"VMware.vSphere.LsClient",
"bin",
$Configuration,
"netcoreapp2.0",
"VMware.vSphere.LsClient.dll")
$netcoreSsoAdminSource = [IO.Path]::Combine(
$PSScriptRoot,
"VMware.vSphere.SsoAdmin.Client",
"VMware.vSphere.SsoAdminClient",
"bin",
$Configuration,
"netcoreapp2.0",
"VMware.vSphere.SsoAdminClient.dll")
$net45SsoAdminSource = [IO.Path]::Combine(
$PSScriptRoot,
"VMware.vSphere.SsoAdmin.Client",
"VMware.vSphere.SsoAdminClient",
"bin",
$Configuration,
"net45",
"VMware.vSphere.SsoAdminClient.dll")
$netcoreUtilsSource = [IO.Path]::Combine(
$PSScriptRoot,
"VMware.vSphere.SsoAdmin.Client",
"VMware.vSphere.SsoAdmin.Utils",
"bin",
$Configuration,
"netcoreapp2.0",
"VMware.vSphere.SsoAdmin.Utils.dll")
$net45UtilsSource = [IO.Path]::Combine(
$PSScriptRoot,
"VMware.vSphere.SsoAdmin.Client",
"VMware.vSphere.SsoAdmin.Utils",
"bin",
$Configuration,
"net45",
"VMware.vSphere.SsoAdmin.Utils.dll")
$netcoreTarget = Join-Path $OutputFolder "netcoreapp2.0"
$net45Target = Join-Path $OutputFolder "net45"
Copy-Item -Path $netcoreLsSource -Destination $netcoreTarget -Force
Copy-Item -Path $net45LsSource -Destination $net45Target -Force
Copy-Item -Path $netcoreSsoAdminSource -Destination $netcoreTarget -Force
Copy-Item -Path $net45SsoAdminSource -Destination $net45Target -Force
Copy-Item -Path $netcoreUtilsSource -Destination $netcoreTarget -Force
Copy-Item -Path $net45UtilsSource -Destination $net45Target -Force
}
}
function Test {
if (-not [string]::IsNullOrEmpty($TestVc) -and `
-not [string]::IsNullOrEmpty($TestVcUser) -and `
-not [string]::IsNullOrEmpty($TestVcPassword)) {
# Run Tests in external process because it will load build output binaries
LogInfo "Run VC integration tests"
$usePowerShell = (Get-Process -Id $pid).ProcessName
$testLauncherScript = Join-Path (Join-Path $PSScriptRoot 'test') 'RunTests.ps1'
$arguments = "-Command $testLauncherScript -VcAddress $TestVc -VcUser $TestVcUser -VcUserPassword $TestVcPassword"
Start-Process `
-FilePath $usePowerShell `
-ArgumentList $arguments `
-PassThru `
-NoNewWindow | `
Wait-Process
}
}
# 1. Test Build Tools
LogInfo "Test build tools are available"
Test-BuildToolsAreAvailable
# 2. Build
LogInfo "Build"
Build
# 3. Publish
$OutputFolder = Split-Path $PSScriptRoot
LogInfo "Publish binaries to '$OutputFolder'"
Publish $OutputFolder
# 4. Test
Test

View File

@@ -0,0 +1,47 @@
#**************************************************************************
# Copyright (c) VMware, Inc. All rights reserved.
#**************************************************************************
param(
[Parameter(Mandatory = $true)]
[string]
$VcAddress,
[Parameter(Mandatory = $true)]
[string]
$VcUser,
[Parameter(Mandatory = $true)]
[string]
$VcUserPassword
)
# Import Vmware.vSphere.SsoAdmin Module
$modulePath = Join-Path (Split-Path $PSScriptRoot | Split-Path) "VMware.vSphere.SsoAdmin.psd1"
Import-Module $modulePath
$script:lsClient = $null
Describe "Lookup Service Client Integration Tests" {
Context "Retrieval of SsoAdmin API Url" {
BeforeAll {
## Create LsClient
$skipCertificateCheckValidator = New-Object `
'VMware.vSphere.SsoAdmin.Utils.AcceptAllX509CertificateValidator'
$script:lsClient = New-Object `
'VMware.vSphere.LsClient.LookupServiceClient' `
-ArgumentList @($VCAddress, $skipCertificateCheckValidator)
}
It 'Gets SsoAdmin API Url' {
# Act
$actual = $script:lsClient.GetSsoAdminEndpointUri()
# Assert
$actual | Should Not Be $null
$actual.ToString().StartsWith("https://$VCAddress/sso-adminserver/sdk/") | Should Be $true
}
}
}

View File

@@ -0,0 +1,38 @@
#**************************************************************************
# Copyright (c) VMware, Inc. All rights reserved.
#**************************************************************************
param(
[Parameter(Mandatory = $true)]
[string]
$VcAddress,
[Parameter(Mandatory = $true)]
[string]
$VcUser,
[Parameter(Mandatory = $true)]
[string]
$VcUserPassword
)
function Test-PesterIsAvailable() {
$pesterModule = Get-Module Pester -List
if ($pesterModule -eq $null) {
throw "Pester Module is not available"
}
}
Test-PesterIsAvailable
$testFiles = Get-ChildItem -Path $PSScriptRoot -Filter "*.Tests.ps1"
Invoke-Pester `
-Script @{
Path = $PSScriptRoot
Parameters = @{
VcAddress = $VcAddress
VcUser = $VcUser
VcUserPassword = $VcUserPassword
}
}