go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/tokenserver/appengine/impl/machinetoken/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 machinetoken 16 17 import ( 18 "math/big" 19 "net" 20 "testing" 21 "time" 22 23 "google.golang.org/protobuf/types/known/timestamppb" 24 25 "go.chromium.org/luci/common/clock" 26 27 tokenserver "go.chromium.org/luci/tokenserver/api" 28 bqpb "go.chromium.org/luci/tokenserver/api/bq" 29 "go.chromium.org/luci/tokenserver/api/minter/v1" 30 31 . "github.com/smartystreets/goconvey/convey" 32 33 . "go.chromium.org/luci/common/testing/assertions" 34 ) 35 36 func TestMintedTokenInfo(t *testing.T) { 37 Convey("produces correct row map", t, func() { 38 ctx := testingContext(testingCA) 39 40 info := MintedTokenInfo{ 41 Request: testingRawRequest(ctx), 42 Response: &minter.MachineTokenResponse{ 43 ServiceVersion: "unit-tests/mocked-ver", 44 TokenType: &minter.MachineTokenResponse_LuciMachineToken{ 45 LuciMachineToken: &minter.LuciMachineToken{ 46 MachineToken: "zzzz", 47 Expiry: timestamppb.New(clock.Now(ctx).Add(time.Hour)), 48 }, 49 }, 50 }, 51 TokenBody: &tokenserver.MachineTokenBody{ 52 MachineFqdn: "luci-token-server-test-1.fake.domain", 53 IssuedBy: "signer@testing.host", 54 IssuedAt: 1422936306, 55 Lifetime: 3600, 56 CaId: 123, 57 CertSn: big.NewInt(4096).Bytes(), 58 }, 59 CA: &testingCA, 60 PeerIP: net.ParseIP("127.10.10.10"), 61 RequestID: "gae-request-id", 62 } 63 64 So(info.toBigQueryMessage(), ShouldResembleProto, &bqpb.MachineToken{ 65 CaCommonName: "Fake CA: fake.ca", 66 CaConfigRev: "cfg-updated-rev", 67 CertSerialNumber: "4096", 68 Expiration: ×tamppb.Timestamp{Seconds: 1422939906}, 69 Fingerprint: "2d6ccd34ad7af363159ed4bbe18c0e43", 70 GaeRequestId: "gae-request-id", 71 IssuedAt: ×tamppb.Timestamp{Seconds: 1422936306}, 72 MachineFqdn: "luci-token-server-test-1.fake.domain", 73 PeerIp: "127.10.10.10", 74 ServiceVersion: "unit-tests/mocked-ver", 75 SignatureAlgorithm: minter.SignatureAlgorithm_SHA256_RSA_ALGO, 76 TokenType: tokenserver.MachineTokenType_LUCI_MACHINE_TOKEN, 77 }) 78 }) 79 }