As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Unverified Commit 463884ca authored by Ash McKenzie's avatar Ash McKenzie
Browse files

Ensure context is not nil before processing

parent 4b31496a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -195,6 +195,7 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
conn := newConnection(s.Config, nconn)
var ctxWithLogMetadata context.Context
conn.handle(ctx, s.serverConfig.get(ctx), func(ctx context.Context, sconn *ssh.ServerConn, channel ssh.Channel, requests <-chan *ssh.Request) error {
session := &session{
cfg: s.Config,
Loading
Loading
@@ -236,6 +237,10 @@ func (s *Server) proxyPolicy() (proxyproto.PolicyFunc, error) {
func extractMetaDataFromContext(ctx context.Context) command.LogMetadata {
metadata := command.LogMetadata{}
if ctx == nil {
return metadata
}
if ctx.Value("metadata") != nil {
metadata = ctx.Value("metadata").(command.LogMetadata)
}
Loading
Loading
Loading
Loading
@@ -353,17 +353,23 @@ func TestExtractMetaDataFromContext(t *testing.T) {
rootNameSpace := "flightjs"
project := fmt.Sprintf("%s/Flight", rootNameSpace)
username := "alex-doe"
ctxWithLogMetadata := context.WithValue(context.Background(), "metadata", command.NewLogMetadata(project, username))
ctx := context.WithValue(context.Background(), "metadata", command.NewLogMetadata(project, username))
metadata := extractMetaDataFromContext(ctxWithLogMetadata)
metadata := extractMetaDataFromContext(ctx)
require.Equal(t, command.LogMetadata{Project: project, Username: username, RootNamespace: rootNameSpace}, metadata)
}
func TestExtractMetaDataFromContextWithoutMetaData(t *testing.T) {
ctxWithLogMetadata := context.Background()
metadata := extractMetaDataFromContext(context.Background())
metadata := extractMetaDataFromContext(ctxWithLogMetadata)
require.Equal(t, command.LogMetadata{}, metadata)
}
func TestExtractMetaDataFromNilContext(t *testing.T) {
var ctx context.Context
metadata := extractMetaDataFromContext(ctx)
require.Equal(t, command.LogMetadata{}, metadata)
}
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment