2019-06-11 14:42:29 +02:00
|
|
|
// -*- Mode: Go; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
|
|
/*
|
2021-04-08 16:56:54 +02:00
|
|
|
* Copyright (C) 2014-2021 Canonical Ltd
|
2019-06-11 14:42:29 +02:00
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License version 3 as
|
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-01 18:23:09 +01:00
|
|
|
package daemon_test
|
2019-06-11 14:42:29 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
2024-04-03 22:23:24 +01:00
|
|
|
"io"
|
2019-06-11 14:42:29 +02:00
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
2024-04-03 22:23:24 +01:00
|
|
|
"os"
|
2019-06-11 14:42:29 +02:00
|
|
|
|
|
|
|
|
"gopkg.in/check.v1"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = check.Suite(&pprofDebugSuite{})
|
|
|
|
|
|
|
|
|
|
type pprofDebugSuite struct {
|
2021-03-01 18:23:09 +01:00
|
|
|
apiBaseSuite
|
2019-06-11 14:42:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *pprofDebugSuite) TestGetPprofCmdline(c *check.C) {
|
2021-03-01 18:23:09 +01:00
|
|
|
s.daemon(c)
|
|
|
|
|
|
2019-06-11 14:42:29 +02:00
|
|
|
req, err := http.NewRequest("GET", "/v2/debug/pprof/cmdline", nil)
|
|
|
|
|
c.Assert(err, check.IsNil)
|
2021-03-01 18:23:09 +01:00
|
|
|
// as root
|
2021-04-08 16:56:54 +02:00
|
|
|
s.asRootAuth(req)
|
2019-06-11 14:42:29 +02:00
|
|
|
|
|
|
|
|
rr := httptest.NewRecorder()
|
2021-03-01 18:23:09 +01:00
|
|
|
s.serveHTTP(c, rr, req)
|
2019-06-11 14:42:29 +02:00
|
|
|
|
|
|
|
|
rsp := rr.Result()
|
|
|
|
|
c.Assert(rsp, check.NotNil)
|
|
|
|
|
|
|
|
|
|
c.Assert(rsp.StatusCode, check.Equals, 200)
|
2024-04-03 22:23:24 +01:00
|
|
|
data, err := io.ReadAll(rsp.Body)
|
2019-06-11 14:42:29 +02:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
|
2024-04-03 22:23:24 +01:00
|
|
|
cmdline, err := os.ReadFile("/proc/self/cmdline")
|
2019-06-11 14:42:29 +02:00
|
|
|
c.Assert(err, check.IsNil)
|
|
|
|
|
cmdline = bytes.TrimRight(cmdline, "\x00")
|
|
|
|
|
c.Assert(string(data), check.DeepEquals, string(cmdline))
|
|
|
|
|
}
|