From 9c0d66197bfa60a0c14109a471b6bcdfd61247e1 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 5 Oct 2023 18:28:56 +0300 Subject: feat(tvix/nar-bridge): do pathInfo.Validate() as additional check This should make it quite quick to spot writing code breaking some of the assumptions we have on PathInfo messages ourselves. Change-Id: I480caaec41f8ea5246c3c3081460c7ad12e78569 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9554 Reviewed-by: Connor Brewster Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/nar-bridge/pkg/pathinfosvc/server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'tvix/nar-bridge/pkg/pathinfosvc/server.go') diff --git a/tvix/nar-bridge/pkg/pathinfosvc/server.go b/tvix/nar-bridge/pkg/pathinfosvc/server.go index 464ca6f61b13..d5074a2f3267 100644 --- a/tvix/nar-bridge/pkg/pathinfosvc/server.go +++ b/tvix/nar-bridge/pkg/pathinfosvc/server.go @@ -264,6 +264,20 @@ func (p *PathInfoServiceServer) Get(ctx context.Context, getPathInfoRequest *sto panic("node may not be nil") } + // run Validate on the PathInfo, more as an additional sanity check our code is sound, + // to make sure we populated everything properly, before returning it. + validatedOutPath, err := pathInfo.Validate() + if err != nil { + panic("pathinfo failed validation") + } + if narInfo.StorePath != validatedOutPath.Absolute() { + panic(fmt.Sprintf( + "StorePath returned from Validate() mismatches the one from .narinfo (%s vs %s)", + validatedOutPath.Absolute(), + narInfo.StorePath), + ) + } + return pathInfo, nil // TODO: Deriver, System, CA -- cgit 1.4.1