XuqmGroup-Server/tenant-service/src/test/java/com/xuqm/tenant/controller/InternalSdkControllerTest.java

36 行
1.4 KiB
Java

package com.xuqm.tenant.controller;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.xuqm.tenant.service.ApiKeyService;
import com.xuqm.tenant.service.FeatureServiceManager;
import com.xuqm.tenant.service.SdkAppProvisioningService;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
class InternalSdkControllerTest {
@Test
void validatesApiKeyFromProtectedPostBody() {
ApiKeyService apiKeyService = mock(ApiKeyService.class);
when(apiKeyService.validateApiKey("secret-api-token")).thenReturn("ak_test");
InternalSdkController controller = new InternalSdkController(
mock(SdkAppProvisioningService.class),
mock(FeatureServiceManager.class),
apiKeyService);
ReflectionTestUtils.setField(controller, "internalToken", "internal-only");
var response = controller.validateApiKey(
new InternalSdkController.ApiKeyValidationRequest("secret-api-token"),
"internal-only");
assertThat(response.getStatusCode().value()).isEqualTo(200);
assertThat(response.getBody()).isNotNull();
assertThat(response.getBody().data()).containsEntry("appKey", "ak_test");
verify(apiKeyService).validateApiKey("secret-api-token");
}
}