Back to Repositories

Testing Secret Management Operations in Conductor OSS

This test suite evaluates the SecretClient functionality in the Conductor OSS framework, focusing on secret management operations and tag handling. The tests verify core secret operations including creation, retrieval, tagging, and deletion while ensuring proper error handling and data consistency.

Test Coverage Overview

The test suite provides comprehensive coverage of the SecretClient API functionality, including:

  • Secret creation and deletion operations
  • Tag management (adding, retrieving, deleting)
  • Secret existence verification
  • Secret access control validation
  • Error handling for non-existent secrets

Implementation Analysis

The testing approach utilizes JUnit Jupiter for structured unit testing, implementing a single comprehensive test method that validates the complete lifecycle of secret management. The implementation follows a sequential pattern to test interdependent operations, ensuring state consistency throughout the test execution.

Technical Details

Testing tools and configuration:

  • JUnit Jupiter test framework
  • ConductorClientException handling
  • ClientTestUtil for test client initialization
  • Custom TagObject implementation for secret tagging
  • Assertions for validation checks

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Proper test cleanup and resource management
  • Comprehensive error handling and status code verification
  • Consistent naming conventions for test resources
  • Modular helper methods for reusable test components
  • Clear assertion messages for failure scenarios

conductor-oss/conductor

conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/SecretClientTests.java

            
/*
 * Copyright 2022 Conductor Authors.
 * <p>
 * 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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.
 */
package io.orkes.conductor.client.http;

import java.util.List;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import com.netflix.conductor.client.exception.ConductorClientException;

import io.orkes.conductor.client.SecretClient;
import io.orkes.conductor.client.model.TagObject;
import io.orkes.conductor.client.util.ClientTestUtil;


public class SecretClientTests {
    private final String SECRET_NAME = "test-sdk-java-secret_name";
    private final String SECRET_KEY = "test-sdk-java-secret_key";

    private final SecretClient secretClient = ClientTestUtil.getOrkesClients().getSecretClient();

    @Test
    void testMethods() {
        try {
            secretClient.deleteSecret(SECRET_KEY);
        } catch (ConductorClientException e) {
            if (e.getStatus() != 500) {
                throw e;
            }
        }
        secretClient.putSecret(SECRET_NAME, SECRET_KEY);
        secretClient.setSecretTags(List.of(getTagObject()), SECRET_KEY);
        List<TagObject> tags = secretClient.getSecretTags(SECRET_KEY);
        Assertions.assertEquals(tags.size(), 1);
        Assertions.assertEquals(tags.get(0), getTagObject());
        secretClient.deleteSecretTags(List.of(getTagObject()), SECRET_KEY);
        Assertions.assertEquals(secretClient.getSecretTags(SECRET_KEY).size(), 0);
        Assertions.assertTrue(secretClient.listSecretsThatUserCanGrantAccessTo().contains(SECRET_KEY));
        Assertions.assertTrue(secretClient.listAllSecretNames().contains(SECRET_KEY));
        Assertions.assertEquals(SECRET_NAME, secretClient.getSecret(SECRET_KEY));
        Assertions.assertTrue(secretClient.secretExists(SECRET_KEY));
        secretClient.deleteSecret(SECRET_KEY);
    }

    private TagObject getTagObject() {
        TagObject tagObject = new TagObject();
        tagObject.setKey("department");
        tagObject.setValue("accounts");
        return tagObject;
    }
}