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
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Google.Cloud.SecretManager.V1;
using Xunit;

[Collection(nameof(RegionalSecretManagerFixture))]
public class CreateRegionalSecretWithCloudSqlCredentialsTests
{
private readonly RegionalSecretManagerFixture _fixture;
private readonly CreateRegionalSecretWithCloudSqlCredentialsSample _sample;

public CreateRegionalSecretWithCloudSqlCredentialsTests(RegionalSecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new CreateRegionalSecretWithCloudSqlCredentialsSample();
}

[Fact]
public void CreatesRegionalSecretWithCloudSqlCredentials()
{
SecretName secretName = SecretName.FromProjectLocationSecret(_fixture.ProjectId, _fixture.LocationId, _fixture.RandomId());

try
{
// Run the sample code.
Secret result = _sample.CreateRegionalSecretWithCloudSqlCredentials(
projectId: secretName.ProjectId, locationId: secretName.LocationId, secretId: secretName.SecretId);

// Assert that the secret was created with the Cloud SQL secret type.
Assert.Equal(secretName.SecretId, result.SecretName.SecretId);
Assert.Equal(Secret.Types.SecretType.CloudSqlDbCredentials, result.SecretType);
Assert.NotNull(result.PolicyMember);
Assert.False(string.IsNullOrEmpty(result.PolicyMember.IamPolicyUidPrincipal));
}
finally
{
// Clean the created secret.
_fixture.DeleteSecret(secretName);
}
}
}
Comment thread
YashSaraf11 marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Google.Cloud.SecretManager.V1;
using Xunit;

[Collection(nameof(SecretManagerFixture))]
public class CreateSecretWithTypeTests
{
private readonly SecretManagerFixture _fixture;
private readonly CreateSecretWithTypeSample _sample;

public CreateSecretWithTypeTests(SecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new CreateSecretWithTypeSample();
}

[Theory]
[InlineData(Secret.Types.SecretType.AccessKey)]
[InlineData(Secret.Types.SecretType.Certificate)]
[InlineData(Secret.Types.SecretType.OtherDbCredentials)]
[InlineData(Secret.Types.SecretType.Other)]
public void CreatesSecretWithType(Secret.Types.SecretType secretType)
{
SecretName secretName = new SecretName(_fixture.ProjectId, _fixture.RandomId());

try
{
// Run the sample code.
Secret result = _sample.CreateSecretWithType(
projectId: secretName.ProjectId, secretId: secretName.SecretId, secretType: secretType);

// Assert that the secret was created with the requested type.
Assert.Equal(secretName.SecretId, result.SecretName.SecretId);
Assert.Equal(secretType, result.SecretType);
}
finally
{
// Clean the created secret.
_fixture.DeleteSecret(secretName);
}
}
Comment thread
YashSaraf11 marked this conversation as resolved.
Resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Google.Cloud.SecretManager.V1;
using System;
using Xunit;

[Collection(nameof(RegionalSecretManagerFixture))]
public class EnableRegionalSecretManagedRotationTests
{
private readonly RegionalSecretManagerFixture _fixture;
private readonly EnableRegionalSecretManagedRotationSample _sample;

public EnableRegionalSecretManagedRotationTests(RegionalSecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new EnableRegionalSecretManagedRotationSample();
}

[Fact]
public void EnablesRegionalSecretManagedRotation()
{
// Skip when no Cloud SQL instance/user is configured (e.g. in CI).
if (!_fixture.HasCloudSqlConfig)
{
return;
}

Secret secret = null;
string member = null;
try
{
secret = _fixture.CreateCloudSqlCredentialsSecret(_fixture.RandomId());
member = secret.PolicyMember.IamPolicyUidPrincipal;

// Run the sample code.
SecretVersion version = _sample.EnableRegionalSecretManagedRotation(
projectId: secret.SecretName.ProjectId,
locationId: secret.SecretName.LocationId,
secretId: secret.SecretName.SecretId,
instanceId: _fixture.CloudSqlInstanceId,
username: _fixture.CloudSqlUsername);

// Assert that the first version was created and is enabled.
Assert.Contains(secret.SecretName.SecretId, version.Name);
Assert.Equal(SecretVersion.Types.State.Enabled, version.State);
}
finally
{
try
{
if (member != null)
{
_fixture.RevokeCloudSqlRole(member);
}
}
finally
{
if (secret != null)
{
_fixture.DeleteSecret(secret.SecretName);
}
}
}
}
Comment thread
YashSaraf11 marked this conversation as resolved.
Resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Google.Cloud.SecretManager.V1;
using Xunit;

[Collection(nameof(RegionalSecretManagerFixture))]
public class GetRegionalSecretTypeTests
{
private readonly RegionalSecretManagerFixture _fixture;
private readonly GetRegionalSecretTypeSample _sample;

public GetRegionalSecretTypeTests(RegionalSecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new GetRegionalSecretTypeSample();
}

[Fact]
public void GetsRegionalSecretType()
{
SecretName secretName = SecretName.FromProjectLocationSecret(_fixture.ProjectId, _fixture.LocationId, _fixture.RandomId());
_fixture.Client.CreateSecret(
new Google.Api.Gax.ResourceNames.LocationName(_fixture.ProjectId, _fixture.LocationId),
secretName.SecretId,
new Secret { SecretType = Secret.Types.SecretType.CloudSqlDbCredentials });
try
{
// Run the sample code.
Secret result = _sample.GetRegionalSecretType(
projectId: secretName.ProjectId, locationId: secretName.LocationId, secretId: secretName.SecretId);

Assert.Equal(secretName.SecretId, result.SecretName.SecretId);
Assert.Equal(Secret.Types.SecretType.CloudSqlDbCredentials, result.SecretType);
}
finally
{
_fixture.DeleteSecret(secretName);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using Google.Cloud.SecretManager.V1;
using Xunit;

[Collection(nameof(SecretManagerFixture))]
public class GetSecretTypeTests
{
private readonly SecretManagerFixture _fixture;
private readonly GetSecretTypeSample _sample;

public GetSecretTypeTests(SecretManagerFixture fixture)
{
_fixture = fixture;
_sample = new GetSecretTypeSample();
}

[Fact]
public void GetsSecretType()
{
SecretName secretName = new SecretName(_fixture.ProjectId, _fixture.RandomId());
_fixture.Client.CreateSecret(
_fixture.ProjectName,
secretName.SecretId,
new Secret
{
Replication = new Replication { Automatic = new Replication.Types.Automatic() },
SecretType = Secret.Types.SecretType.Certificate,
});
try
{
// Run the sample code.
Secret result = _sample.GetSecretType(projectId: secretName.ProjectId, secretId: secretName.SecretId);

Assert.Equal(secretName.SecretId, result.SecretName.SecretId);
Assert.Equal(Secret.Types.SecretType.Certificate, result.SecretType);
}
finally
{
_fixture.DeleteSecret(secretName);
}
}
}
Loading
Loading