Skip to content

Commit

Permalink
Add initial test for mapresponse
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
  • Loading branch information
kradalby committed Jun 8, 2023
1 parent f9f6e15 commit 084d1d5
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 19 deletions.
17 changes: 6 additions & 11 deletions hscontrol/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func NewMapper(
}

func (m *Mapper) tempWrap(
mapRequest tailcfg.MapRequest,
machine *types.Machine,
pol *policy.ACLPolicy,
) (*tailcfg.MapResponse, error) {
Expand All @@ -85,7 +84,6 @@ func (m *Mapper) tempWrap(
}

return fullMapResponse(
mapRequest,
pol,
machine,
peers,
Expand All @@ -99,7 +97,6 @@ func (m *Mapper) tempWrap(
}

func fullMapResponse(
mapRequest tailcfg.MapRequest,
pol *policy.ACLPolicy,
machine *types.Machine,
peers types.Machines,
Expand Down Expand Up @@ -185,12 +182,6 @@ func fullMapResponse(
},
}

log.Trace().
Caller().
Str("machine", mapRequest.Hostinfo.Hostname).
// Interface("payload", resp).
Msgf("Generated map response: %s", util.TailMapResponseToString(resp))

return &resp, nil
}

Expand Down Expand Up @@ -292,7 +283,7 @@ func (m Mapper) CreateMapResponse(
machine *types.Machine,
pol *policy.ACLPolicy,
) ([]byte, error) {
mapResponse, err := m.tempWrap(mapRequest, machine, pol)
mapResponse, err := m.tempWrap(machine, pol)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -345,8 +336,12 @@ func (m Mapper) CreateKeepAliveResponse(
return m.marshalMapResponse(keepAliveResponse, machineKey, mapRequest.Compress)
}

// MarshalResponse takes an Tailscale Response, marhsal it to JSON.
// If isNoise is set, then the JSON body will be returned
// If !isNoise and privateKey2019 is set, the JSON body will be sealed in a Nacl box.
func MarshalResponse(
resp interface{},
isNoise bool,
privateKey2019 *key.MachinePrivate,
machineKey key.MachinePublic,
) ([]byte, error) {
Expand All @@ -360,7 +355,7 @@ func MarshalResponse(
return nil, err
}

if privateKey2019 != nil {
if !isNoise && privateKey2019 != nil {
return privateKey2019.SealTo(machineKey, jsonBody), nil
}

Expand Down

0 comments on commit 084d1d5

Please sign in to comment.