...

Source file src/golang.conradwood.net/tests/authtest/authproxy.go

Documentation: golang.conradwood.net/tests/authtest

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"golang.conradwood.net/apis/common"
     7  	pb "golang.conradwood.net/apis/getestservice"
     8  	git "golang.conradwood.net/apis/gitserver"
     9  	"golang.conradwood.net/go-easyops/auth"
    10  	"golang.conradwood.net/go-easyops/authremote"
    11  	"golang.conradwood.net/go-easyops/tokens"
    12  	"golang.conradwood.net/go-easyops/utils"
    13  	"time"
    14  )
    15  
    16  func StartAuthProxy() {
    17  	//p := utils.RandomInt(100)
    18  	//	go create.NewEasyOpsTest(&testserver{}, *port+p)
    19  	time.Sleep(time.Duration(500) * time.Millisecond) // give server some time to register...
    20  	fmt.Printf("Creating easyops client...\n")
    21  	_, err := pb.GetEasyOpsTestClient().CheckSerialisation(authremote.Context(), &pb.Count{})
    22  	utils.Bail("failed", err)
    23  
    24  }
    25  func (*testserver) CheckSerialisation(ctx context.Context, req *pb.Count) (*common.Void, error) {
    26  	fmt.Printf("Running serialisation test...(Count=%d)\n", req.Count)
    27  	fmt.Printf("Inbound User: %s\n", auth.CurrentUserString(ctx))
    28  	if req.Count == 0 {
    29  		tokens.SetServiceTokenParameter(servicetokens[0])
    30  		return pb.GetEasyOpsTestClient().CheckSerialisation(ctx, &pb.Count{Count: req.Count + 1})
    31  	}
    32  	foo, err := auth.SerialiseContext(ctx)
    33  	utils.Bail("Failed to serialise context", err)
    34  	fmt.Printf("Serialised context: %s\n", string(foo))
    35  	new_ctx, err := auth.RecreateContextWithTimeout(time.Duration(10)*time.Second, foo)
    36  	utils.Bail("Failed to fix context", err)
    37  	fmt.Printf("Restored User: %s\n", auth.CurrentUserString(new_ctx))
    38  	// now try a gitserver call...
    39  	r, err := git.GetGIT2Client().RepoByID(new_ctx, &git.ByIDRequest{ID: 2})
    40  	utils.Bail("Failed to call git", err)
    41  	fmt.Printf("Git Repo: %s\n", r.ArtefactName)
    42  	return &common.Void{}, nil
    43  }
    44  

View as plain text