Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add startup conditions #11305

Merged
merged 2 commits into from
Nov 1, 2023
Merged
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
Expand Up @@ -18,14 +18,23 @@

import com.alibaba.nacos.api.exception.runtime.NacosRuntimeException;
import com.alibaba.nacos.core.remote.tls.RpcServerTlsConfig;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.mock.env.MockEnvironment;

import java.lang.reflect.Field;

public class DefaultTlsContextBuilderTest {

private ConfigurableEnvironment environment;

@Before
public void setUp() throws Exception {
environment = new MockEnvironment();
EnvUtil.setEnvironment(environment);
RpcServerTlsConfig.getInstance().setEnableTls(true);
}

Expand All @@ -40,6 +49,7 @@ public void tearDown() throws Exception {
RpcServerTlsConfig.getInstance().setProtocols(null);
RpcServerTlsConfig.getInstance().setTrustCollectionCertFile(null);
RpcServerTlsConfig.getInstance().setSslProvider("");
clearRpcServerTlsConfigInstance();
}

@Test(expected = IllegalArgumentException.class)
Expand Down Expand Up @@ -101,4 +111,10 @@ public void testGetSslContextForNonExistFile() {
grpcServerConfig.setCertChainFile("non-exist-cert.pem");
DefaultTlsContextBuilder.getSslContext(RpcServerTlsConfig.getInstance());
}

private static void clearRpcServerTlsConfigInstance() throws Exception {
Field instanceField = RpcServerTlsConfig.class.getDeclaredField("instance");
instanceField.setAccessible(true);
instanceField.set(null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
package com.alibaba.nacos.core.remote.grpc.negotiator.tls;

import com.alibaba.nacos.core.remote.tls.RpcServerTlsConfig;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.mock.env.MockEnvironment;

import java.lang.reflect.Field;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

public class DefaultTlsProtocolNegotiatorBuilderTest {

private ConfigurableEnvironment environment;

private DefaultTlsProtocolNegotiatorBuilder builder;

@Before
public void setUp() throws Exception {
environment = new MockEnvironment();
EnvUtil.setEnvironment(environment);
builder = new DefaultTlsProtocolNegotiatorBuilder();
}

Expand All @@ -38,6 +47,7 @@ public void tearDown() throws Exception {
RpcServerTlsConfig.getInstance().setEnableTls(false);
RpcServerTlsConfig.getInstance().setCertChainFile(null);
RpcServerTlsConfig.getInstance().setCertPrivateKey(null);
clearRpcServerTlsConfigInstance();
}

@Test
Expand All @@ -52,4 +62,10 @@ public void testBuildEnabled() {
RpcServerTlsConfig.getInstance().setCertChainFile("test-server-cert.pem");
assertNotNull(builder.build());
}

private static void clearRpcServerTlsConfigInstance() throws Exception {
Field instanceField = RpcServerTlsConfig.class.getDeclaredField("instance");
instanceField.setAccessible(true);
instanceField.set(null, null);
}
}
Loading