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

[#11320] Add validation of parentApplicationName #11321

Merged
merged 1 commit into from
Aug 6, 2024
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 @@ -26,6 +26,7 @@
import com.navercorp.pinpoint.common.server.bo.SpanChunkBo;
import com.navercorp.pinpoint.common.server.bo.SpanEventBo;
import com.navercorp.pinpoint.common.server.bo.SpanEventComparator;
import com.navercorp.pinpoint.common.util.IdValidateUtils;
import com.navercorp.pinpoint.common.util.StringUtils;
import com.navercorp.pinpoint.grpc.MessageFormatUtils;
import com.navercorp.pinpoint.grpc.trace.PAcceptEvent;
Expand Down Expand Up @@ -133,7 +134,7 @@
}

final String parentApplicationName = parentInfo.getParentApplicationName();
if (StringUtils.hasLength(parentApplicationName)) {
if (validateParentApplicationName(parentApplicationName)) {
spanBo.setParentApplicationId(parentApplicationName);
}
spanBo.setParentApplicationServiceType((short) parentInfo.getParentApplicationType());
Expand All @@ -153,6 +154,16 @@
return spanBo;
}

private boolean validateParentApplicationName(String parentApplicationName) {
if (StringUtils.isEmpty(parentApplicationName)) {
return false;

Check warning on line 159 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java#L159

Added line #L159 was not covered by tests
}
if (!IdValidateUtils.validateId(parentApplicationName)) {
throw new IllegalArgumentException("Invalid parentApplicationName " + parentApplicationName);
}
return true;

Check warning on line 164 in commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java

View check run for this annotation

Codecov / codecov/patch

commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/grpc/GrpcSpanBinder.java#L164

Added line #L164 was not covered by tests
}

private String getExceptionMessage(PIntStringValue exceptionInfo) {
if (exceptionInfo.hasStringValue()) {
return exceptionInfo.getStringValue().getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.navercorp.pinpoint.common.server.bo.grpc;

import com.navercorp.pinpoint.grpc.trace.PAcceptEvent;
import com.navercorp.pinpoint.grpc.trace.PParentInfo;
import com.navercorp.pinpoint.grpc.trace.PSpan;
import com.navercorp.pinpoint.grpc.trace.PTransactionId;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

class GrpcSpanBinderTest {

@Test
void bindSpanBo_InvalidParentApplicationName() {

BindAttribute bindAttribute = new BindAttribute("agentId", "applicationName", 1234, System.currentTimeMillis());
GrpcSpanBinder grpcSpanBinder = new GrpcSpanBinder();

PAcceptEvent event = PAcceptEvent.newBuilder()
.setParentInfo(PParentInfo.newBuilder()
.setParentApplicationName("##invalidId")
.build())
.build();
PTransactionId transactionId = PTransactionId.newBuilder()
.setAgentId("agentId")
.setAgentStartTime(1234)
.setSequence(1)
.build();

PSpan span = PSpan.newBuilder()
.setTransactionId(transactionId)
.setAcceptEvent(event)
.build();

Assertions.assertThrows(IllegalArgumentException.class, () -> grpcSpanBinder.newSpanBo(span, bindAttribute));
}
}