Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into patch-12189
Browse files Browse the repository at this point in the history
  • Loading branch information
totalo committed Aug 22, 2024
2 parents 4ceb039 + a9a0df2 commit 3d8e14d
Show file tree
Hide file tree
Showing 253 changed files with 7,285 additions and 4,576 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ name: "Continuous Integration"
on:
push:
branches: [ master, develop, v1.x-develop, v1.X ]
pull_request:
pull_request_target:
branches: [ develop, v1.x-develop ]

permissions:
contents: read # to fetch code (actions/checkout)
permissions: read-all

jobs:
ci:
Expand All @@ -21,16 +20,20 @@ jobs:
java: [8]
steps:
- name: "Cache Maven Repos"
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- if: github.event_name == 'pull_request_target'
run: echo "REF=refs/pull/${{ github.event.number }}/merge" >> "$GITHUB_ENV"
- name: "Checkout"
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: "Set up JDK ${{ matrix.java }}"
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'
Expand All @@ -44,7 +47,11 @@ jobs:
- name: "Test With Maven"
run: mvn -Prelease-nacos clean test -DtrimStackTrace=false -e -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
- name: "Codecov"
uses: codecov/[email protected]
uses: codecov/[email protected]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
verbose: true
fail_ci_if_error: true
files: ./address/target/site/jacoco/jacoco.xml,./api/target/site/jacoco/jacoco.xml,./auth/target/site/jacoco/jacoco.xml,./client/target/site/jacoco/jacoco.xml,./common/target/site/jacoco/jacoco.xml,./config/target/site/jacoco/jacoco.xml,./consistency/target/site/jacoco/jacoco.xml,./console/target/site/jacoco/jacoco.xml,./core/target/site/jacoco/jacoco.xml,./logger-adapter-impl/log4j2-adapter/target/site/jacoco/jacoco.xml,./logger-adapter-impl/logback-adapter-12/target/site/jacoco/jacoco.xml,./naming/target/site/jacoco/jacoco.xml,./persistence/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-auth-plugin/target/site/jacoco/jacoco.xml,./plugin-default-impl/nacos-default-control-plugin/target/site/jacoco/jacoco.xml,./plugin/auth/target/site/jacoco/jacoco.xml,./plugin/config/target/site/jacoco/jacoco.xml,./plugin/control/target/site/jacoco/jacoco.xml,./plugin/datasource/target/site/jacoco/jacoco.xml,./plugin/encryption/target/site/jacoco/jacoco.xml,./plugin/environment/target/site/jacoco/jacoco.xml,./plugin/trace/target/site/jacoco/jacoco.xml,./prometheus/target/site/jacoco/jacoco.xml,./sys/target/site/jacoco/jacoco.xml
token: ${{ secrets.CODECOV_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ test/logs
derby.log
yarn.lock
.flattened-pom.xml
lefthook.yml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ You can view the full documentation from the [Nacos website](https://nacos.io/en

You can also read this online eBook from the [NACOS ARCHITECTURE & PRINCIPLES](https://www.yuque.com/nacos/ebook/kbyo6n).

All the latest and long-term notice can also be found here from [Github notice issue](https://github.com/alibaba/nacos/labels/notice).
All the latest and long-term notice can also be found here from [GitHub notice issue](https://github.com/alibaba/nacos/labels/notice).

## Contributing

Expand Down Expand Up @@ -134,7 +134,7 @@ https://cn.aliyun.com/product/aliware/mse?spm=nacos-website.topbar.0.0.0
## Download

- [Nacos Official Website](https://nacos.io/download/nacos-server)
- [Github Release](https://github.com/alibaba/nacos/releases)
- [GitHub Release](https://github.com/alibaba/nacos/releases)

## Who is using

Expand Down
4 changes: 4 additions & 0 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-util</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/PropertyKeyConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ public class PropertyKeyConst {

public static final String CLIENT_MODULE_TYPE = "clientModuleType";

/**
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
*/
public static final String IS_USE_RAM_INFO_PARSING = "isUseRamInfoParsing";

/**
* Get the key value of some variable value from the system property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public interface SystemPropertyKeyConst {
* It is also supported by the -D parameter.
*/
String IS_USE_ENDPOINT_PARSING_RULE = "nacos.use.endpoint.parsing.rule";

/**
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
*/
String IS_USE_RAM_INFO_PARSING = "nacos.use.ram.info.parsing";
}
15 changes: 12 additions & 3 deletions api/src/main/java/com/alibaba/nacos/api/common/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public class Constants {

public static final String NULL = "";

public static final String DATAID = "dataId";

public static final String DATA_ID = "dataId";

public static final String TENANT = "tenant";

public static final String GROUP = "group";


public static final String NAMESPACE_ID = "namespaceId";

public static final String LAST_MODIFIED = "Last-Modified";

public static final String ACCEPT_ENCODING = "Accept-Encoding";
Expand Down Expand Up @@ -243,6 +247,11 @@ public class Constants {

public static final String CONFIG_GRAY_LABEL = "nacos.config.gray.label";

/**
* Since 2.3.3, For some situation like java agent using nacos-client which can't use env ram info.
*/
public static final String DEFAULT_USE_RAM_INFO_PARSING = "true";

/**
* The constants in config directory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected String getResourceName(Request request) {
dataId = ((AbstractConfigRequest) request).getDataId();
} else {
dataId = (String) ReflectUtils
.getFieldValue(request, com.alibaba.nacos.api.common.Constants.DATAID, StringUtils.EMPTY);
.getFieldValue(request, com.alibaba.nacos.api.common.Constants.DATA_ID, StringUtils.EMPTY);
}
return StringUtils.isBlank(dataId) ? StringUtils.EMPTY : dataId;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.auth.parser.http;

import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.common.utils.NamespaceUtil;
import com.alibaba.nacos.common.utils.StringUtils;

Expand All @@ -31,8 +32,11 @@ public class ConfigHttpResourceParser extends AbstractHttpResourceParser {

@Override
protected String getNamespaceId(HttpServletRequest request) {
return NamespaceUtil.processNamespaceParameter(request.getParameter("tenant"));

String namespaceId = request.getParameter(Constants.NAMESPACE_ID);
if (StringUtils.isBlank(namespaceId)) {
namespaceId = request.getParameter(Constants.TENANT);
}
return NamespaceUtil.processNamespaceParameter(namespaceId);
}

@Override
Expand All @@ -43,7 +47,7 @@ protected String getGroup(HttpServletRequest request) {

@Override
protected String getResourceName(HttpServletRequest request) {
String dataId = request.getParameter(com.alibaba.nacos.api.common.Constants.DATAID);
String dataId = request.getParameter(com.alibaba.nacos.api.common.Constants.DATA_ID);
return StringUtils.isBlank(dataId) ? StringUtils.EMPTY : dataId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void setUp() throws Exception {
Mockito.when(request.getParameter(eq(CommonParams.SERVICE_NAME))).thenReturn("testS");
Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testCNs");
Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testCG");
Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD");
Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD");
}

@Test
Expand Down Expand Up @@ -109,7 +109,7 @@ void testParseResourceWithConfigType() throws NoSuchMethodException {
Resource actual = httpProtocolAuthService.parseResource(request, secured);
assertEquals(SignType.CONFIG, actual.getType());
assertEquals("testD", actual.getName());
assertEquals("testCNs", actual.getNamespaceId());
assertEquals("testNNs", actual.getNamespaceId());
assertEquals("testCG", actual.getGroup());
assertNotNull(actual.getProperties());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.alibaba.nacos.auth.config;

import com.alibaba.nacos.auth.mock.MockAuthPluginServiceB;
import com.alibaba.nacos.sys.module.ModuleState;
import com.alibaba.nacos.sys.utils.ApplicationUtils;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -45,7 +46,6 @@ class AuthModuleStateBuilderTest {
void setUp() throws Exception {
when(context.getBean(AuthConfigs.class)).thenReturn(authConfigs);
ApplicationUtils.injectContext(context);
when(authConfigs.getNacosAuthSystemType()).thenReturn("nacos");
}

@AfterEach
Expand All @@ -54,10 +54,32 @@ void tearDown() throws Exception {

@Test
void testBuild() {
when(authConfigs.getNacosAuthSystemType()).thenReturn("nacos");

ModuleState actual = new AuthModuleStateBuilder().build();
assertFalse((Boolean) actual.getStates().get(AUTH_ENABLED));
assertFalse((Boolean) actual.getStates().get("login_page_enabled"));
assertEquals("nacos", actual.getStates().get("auth_system_type"));
assertTrue((Boolean) actual.getStates().get("auth_admin_request"));

when(authConfigs.getNacosAuthSystemType()).thenReturn(MockAuthPluginServiceB.TEST_PLUGIN);
ModuleState actual2 = new AuthModuleStateBuilder().build();
assertTrue((Boolean) actual2.getStates().get("login_page_enabled"));
assertEquals(MockAuthPluginServiceB.TEST_PLUGIN, actual2.getStates().get("auth_system_type"));
assertFalse((Boolean) actual2.getStates().get("auth_admin_request"));
}

@Test
void testCacheable() {
AuthModuleStateBuilder authModuleStateBuilder = new AuthModuleStateBuilder();
authModuleStateBuilder.build();
boolean cacheable = authModuleStateBuilder.isCacheable();
assertFalse(cacheable);

when(authConfigs.getNacosAuthSystemType()).thenReturn(MockAuthPluginServiceB.TEST_PLUGIN);
AuthModuleStateBuilder authModuleStateBuilder2 = new AuthModuleStateBuilder();
authModuleStateBuilder2.build();
boolean cacheable2 = authModuleStateBuilder2.isCacheable();
assertTrue(cacheable2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 1999-2021 Alibaba Group Holding Ltd.
*
* 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
*
* http://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.
*/

package com.alibaba.nacos.auth.mock;

import com.alibaba.nacos.plugin.auth.api.IdentityContext;
import com.alibaba.nacos.plugin.auth.api.Permission;
import com.alibaba.nacos.plugin.auth.api.Resource;
import com.alibaba.nacos.plugin.auth.constant.ActionTypes;
import com.alibaba.nacos.plugin.auth.spi.server.AuthPluginService;

import java.util.Collection;
import java.util.Collections;

public class MockAuthPluginServiceB implements AuthPluginService {

public static final String TEST_PLUGIN = "testB";

public static final String IDENTITY_TEST_KEY = "identity-test-key";

@Override
public Collection<String> identityNames() {
return Collections.singletonList(IDENTITY_TEST_KEY);
}

@Override
public boolean enableAuth(ActionTypes action, String type) {
return true;
}

@Override
public boolean validateIdentity(IdentityContext identityContext, Resource resource) {
return false;
}

@Override
public Boolean validateAuthority(IdentityContext identityContext, Permission permission) {
return false;
}

@Override
public String getAuthServiceName() {
return TEST_PLUGIN;
}

@Override
public boolean isLoginEnabled() {
return true;
}

@Override
public boolean isAdminRequest() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,49 @@ void testParseWithFullContext() throws NoSuchMethodException {
Secured secured = getMethodSecure();
Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs");
Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG");
Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD");
Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD");
Resource actual = resourceParser.parse(request, secured);
assertEquals("testNs", actual.getNamespaceId());
assertEquals("testG", actual.getGroup());
assertEquals("testD", actual.getName());
assertEquals(Constants.Config.CONFIG_MODULE, actual.getType());
}

@Test
@Secured(signType = Constants.Config.CONFIG_MODULE)
void testParseWithNamespaceId() throws NoSuchMethodException {
Secured secured = getMethodSecure();
Mockito.when(request.getParameter(eq("namespaceId"))).thenReturn("testNs");
Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG");
Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD");
Resource actual = resourceParser.parse(request, secured);
assertEquals("testNs", actual.getNamespaceId());
assertEquals("testG", actual.getGroup());
assertEquals("testD", actual.getName());
assertEquals(Constants.Config.CONFIG_MODULE, actual.getType());
}

@Test
@Secured(signType = Constants.Config.CONFIG_MODULE)
void testParseWithNamespaceIdFirst() throws NoSuchMethodException {
Secured secured = getMethodSecure();
Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs");
Mockito.when(request.getParameter(eq("namespaceId"))).thenReturn("testNsFirst");
Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG");
Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD");
Resource actual = resourceParser.parse(request, secured);
assertEquals("testNsFirst", actual.getNamespaceId());
assertEquals("testG", actual.getGroup());
assertEquals("testD", actual.getName());
assertEquals(Constants.Config.CONFIG_MODULE, actual.getType());
}

@Test
@Secured(signType = Constants.Config.CONFIG_MODULE)
void testParseWithoutNamespace() throws NoSuchMethodException {
Secured secured = getMethodSecure();
Mockito.when(request.getParameter(eq(Constants.GROUP))).thenReturn("testG");
Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD");
Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD");
Resource actual = resourceParser.parse(request, secured);
assertEquals(StringUtils.EMPTY, actual.getNamespaceId());
assertEquals("testG", actual.getGroup());
Expand All @@ -82,7 +111,7 @@ void testParseWithoutNamespace() throws NoSuchMethodException {
void testParseWithoutGroup() throws NoSuchMethodException {
Secured secured = getMethodSecure();
Mockito.when(request.getParameter(eq("tenant"))).thenReturn("testNs");
Mockito.when(request.getParameter(eq(Constants.DATAID))).thenReturn("testD");
Mockito.when(request.getParameter(eq(Constants.DATA_ID))).thenReturn("testD");
Resource actual = resourceParser.parse(request, secured);
assertEquals("testNs", actual.getNamespaceId());
assertEquals(StringUtils.EMPTY, actual.getGroup());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
#

com.alibaba.nacos.auth.mock.MockAuthPluginService
com.alibaba.nacos.auth.mock.MockAuthPluginServiceB
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ public Boolean login(Properties properties) {
tokenTtl = Long.parseLong(identityContext.getParameter(NacosAuthLoginConstant.TOKENTTL));
tokenRefreshWindow = tokenTtl / 10;
lastRefreshTime = System.currentTimeMillis();
loginIdentityContext = new LoginIdentityContext();
loginIdentityContext.setParameter(NacosAuthLoginConstant.ACCESSTOKEN,

LoginIdentityContext newCtx = new LoginIdentityContext();
newCtx.setParameter(NacosAuthLoginConstant.ACCESSTOKEN,
identityContext.getParameter(NacosAuthLoginConstant.ACCESSTOKEN));
this.loginIdentityContext = newCtx;
}
return true;
}
Expand Down
Loading

0 comments on commit 3d8e14d

Please sign in to comment.