go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/tokenserver/appengine/impl/projectscope/bigquery_log_test.go (about)

     1  // Copyright 2017 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package projectscope
    16  
    17  import (
    18  	"net"
    19  	"testing"
    20  
    21  	"google.golang.org/protobuf/types/known/timestamppb"
    22  
    23  	bqpb "go.chromium.org/luci/tokenserver/api/bq"
    24  	"go.chromium.org/luci/tokenserver/api/minter/v1"
    25  
    26  	. "github.com/smartystreets/goconvey/convey"
    27  	. "go.chromium.org/luci/common/testing/assertions"
    28  )
    29  
    30  func TestMintedTokenInfo(t *testing.T) {
    31  	t.Parallel()
    32  
    33  	Convey("produces correct row map", t, func() {
    34  		info := MintedTokenInfo{
    35  			Request: &minter.MintProjectTokenRequest{
    36  				MinValidityDuration: 3600,
    37  				AuditTags:           []string{"k:v"},
    38  				LuciProject:         "someproject",
    39  			},
    40  			Response: &minter.MintProjectTokenResponse{
    41  				ServiceAccountEmail: "foo@bar.com",
    42  				AccessToken:         "blah",
    43  				ServiceVersion:      "unit-tests/mocked-ver",
    44  			},
    45  			RequestedAt: &timestamppb.Timestamp{Seconds: 1},
    46  			Expiration:  &timestamppb.Timestamp{Seconds: 1},
    47  			PeerIP:      net.ParseIP("127.10.10.10"),
    48  			RequestID:   "gae-request-id",
    49  			AuthDBRev:   123,
    50  		}
    51  
    52  		So(info.toBigQueryMessage(), ShouldResembleProto, &bqpb.ProjectToken{
    53  			Fingerprint:    "8b7df143d91c716ecfa5fc1730022f6b",
    54  			ServiceAccount: "foo@bar.com",
    55  			LuciProject:    "someproject",
    56  			Expiration:     &timestamppb.Timestamp{Seconds: 1},
    57  			RequestedAt:    &timestamppb.Timestamp{Seconds: 1},
    58  			AuditTags:      []string{"k:v"},
    59  			PeerIp:         "127.10.10.10",
    60  			ServiceVersion: "unit-tests/mocked-ver",
    61  			GaeRequestId:   "gae-request-id",
    62  			AuthDbRev:      123,
    63  		})
    64  	})
    65  }