Fix Sentry Debug Regex
that was ignoring composed messages including a newline. Also, add regression test.
This commit is contained in:

committed by
Sebastian Serth

parent
6e069f5d8a
commit
e0419c2e58
@@ -19,7 +19,7 @@ var (
|
|||||||
timeDebugMessageFormatEnd = `%s; ec=$?; ` + timeDebugMessageFormat + ` && exit $ec`
|
timeDebugMessageFormatEnd = `%s; ec=$?; ` + timeDebugMessageFormat + ` && exit $ec`
|
||||||
|
|
||||||
timeDebugMessagePattern = regexp.MustCompile(
|
timeDebugMessagePattern = regexp.MustCompile(
|
||||||
`(?P<before>.*)\x1EPoseidon (?P<text>.+) (?P<time>\d{13})\x1E(?P<after>.*)`)
|
`(?P<before>[\S\s]*?)\x1EPoseidon (?P<text>[^\x1E]+) (?P<time>\d{13})\x1E(?P<after>.*)`)
|
||||||
timeDebugMessagePatternStart = regexp.MustCompile(`\x1EPoseidon`)
|
timeDebugMessagePatternStart = regexp.MustCompile(`\x1EPoseidon`)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -57,15 +57,22 @@ func (s *SentryDebugWriter) Write(p []byte) (n int, err error) {
|
|||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
go s.handleTimeDebugMessage(match)
|
if len(match["before"]) > 0 {
|
||||||
|
var count int
|
||||||
lengthRemainingData := len(match["before"]) + len(match["after"])
|
count, err = s.Write(match["before"])
|
||||||
if lengthRemainingData > 0 {
|
n += count
|
||||||
count, err := s.Write(append(match["before"], match["after"]...))
|
|
||||||
return len(p) - (lengthRemainingData - count), err
|
|
||||||
} else {
|
|
||||||
return len(p), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go s.handleTimeDebugMessage(match)
|
||||||
|
n += len(p) - len(match["before"]) - len(match["after"])
|
||||||
|
|
||||||
|
if len(match["after"]) > 0 {
|
||||||
|
var count int
|
||||||
|
count, err = s.Write(match["after"])
|
||||||
|
n += count
|
||||||
|
}
|
||||||
|
|
||||||
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SentryDebugWriter) Close(exitCode int) {
|
func (s *SentryDebugWriter) Close(exitCode int) {
|
||||||
|
@@ -21,6 +21,18 @@ func TestSentryDebugWriter_Write(t *testing.T) {
|
|||||||
assert.NotContains(t, buf.String(), description)
|
assert.NotContains(t, buf.String(), description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSentryDebugWriter_WriteComposed(t *testing.T) {
|
||||||
|
buf := &bytes.Buffer{}
|
||||||
|
w := SentryDebugWriter{Target: buf, Ctx: context.Background()}
|
||||||
|
|
||||||
|
data := "Hello World!\r\n\x1EPoseidon unset 1678540012404\x1E\x1EPoseidon /sbin/setuser user 1678540012408\x1E"
|
||||||
|
count, err := w.Write([]byte(data))
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, len(data), count)
|
||||||
|
assert.Contains(t, buf.String(), "Hello World!")
|
||||||
|
}
|
||||||
|
|
||||||
func TestSentryDebugWriter_Close(t *testing.T) {
|
func TestSentryDebugWriter_Close(t *testing.T) {
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
s := NewSentryDebugWriter(buf, context.Background())
|
s := NewSentryDebugWriter(buf, context.Background())
|
||||||
|
@@ -89,7 +89,7 @@ func (s *E2ETestSuite) TestUserNomad() {
|
|||||||
s.Run("privileged", func() {
|
s.Run("privileged", func() {
|
||||||
stdout, _, _ := ExecuteNonInteractive(&s.Suite, tests.DefaultEnvironmentIDAsInteger,
|
stdout, _, _ := ExecuteNonInteractive(&s.Suite, tests.DefaultEnvironmentIDAsInteger,
|
||||||
&dto.ExecutionRequest{Command: "id --name --user", PrivilegedExecution: true}, nil)
|
&dto.ExecutionRequest{Command: "id --name --user", PrivilegedExecution: true}, nil)
|
||||||
s.Require().Equal("root\r\n", stdout)
|
s.Contains(stdout, "root")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ func (s *E2ETestSuite) TestCommandHead() {
|
|||||||
s.Require().Error(err)
|
s.Require().Error(err)
|
||||||
s.Equal(err, &websocket.CloseError{Code: websocket.CloseNormalClosure})
|
s.Equal(err, &websocket.CloseError{Code: websocket.CloseNormalClosure})
|
||||||
stdout, _, _ := helpers.WebSocketOutputMessages(messages)
|
stdout, _, _ := helpers.WebSocketOutputMessages(messages)
|
||||||
s.Contains(stdout, fmt.Sprintf("%s\r\n%s\r\n", hello, hello))
|
s.Regexp(fmt.Sprintf(`(%s\r\n?){2}`, hello), stdout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *E2ETestSuite) TestCommandMake() {
|
func (s *E2ETestSuite) TestCommandMake() {
|
||||||
|
Reference in New Issue
Block a user