go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/tokenserver/appengine/impl/delegation/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 delegation 16 17 import ( 18 "net" 19 "testing" 20 21 "google.golang.org/protobuf/types/known/timestamppb" 22 23 "go.chromium.org/luci/server/auth/delegation/messages" 24 "go.chromium.org/luci/tokenserver/api/admin/v1" 25 bqpb "go.chromium.org/luci/tokenserver/api/bq" 26 "go.chromium.org/luci/tokenserver/api/minter/v1" 27 28 . "github.com/smartystreets/goconvey/convey" 29 . "go.chromium.org/luci/common/testing/assertions" 30 ) 31 32 func TestMintedTokenInfo(t *testing.T) { 33 t.Parallel() 34 35 Convey("produces correct row map", t, func() { 36 info := MintedTokenInfo{ 37 Request: &minter.MintDelegationTokenRequest{ 38 ValidityDuration: 3600, 39 Intent: "intent string", 40 Tags: []string{"k:v"}, 41 }, 42 Response: &minter.MintDelegationTokenResponse{ 43 Token: "blah", 44 ServiceVersion: "unit-tests/mocked-ver", 45 DelegationSubtoken: &messages.Subtoken{ 46 Kind: messages.Subtoken_BEARER_DELEGATION_TOKEN, 47 SubtokenId: 1234, 48 DelegatedIdentity: "user:delegated@example.com", 49 RequestorIdentity: "user:requestor@example.com", 50 CreationTime: 1422936306, 51 ValidityDuration: 3600, 52 Audience: []string{"user:audience@example.com"}, 53 Services: []string{"*"}, 54 Tags: []string{"k:v"}, 55 }, 56 }, 57 ConfigRev: "config-rev", 58 Rule: &admin.DelegationRule{ 59 Name: "rule-name", 60 }, 61 PeerIP: net.ParseIP("127.10.10.10"), 62 RequestID: "gae-request-id", 63 AuthDBRev: 123, 64 } 65 66 So(info.toBigQueryMessage(), ShouldResembleProto, &bqpb.DelegationToken{ 67 AuthDbRev: 123, 68 ConfigRev: "config-rev", 69 ConfigRule: "rule-name", 70 DelegatedIdentity: "user:delegated@example.com", 71 Expiration: ×tamppb.Timestamp{Seconds: 1422939906}, 72 Fingerprint: "8b7df143d91c716ecfa5fc1730022f6b", 73 GaeRequestId: "gae-request-id", 74 IssuedAt: ×tamppb.Timestamp{Seconds: 1422936306}, 75 PeerIp: "127.10.10.10", 76 RequestedIntent: "intent string", 77 RequestedValidity: 3600, 78 RequestorIdentity: "user:requestor@example.com", 79 ServiceVersion: "unit-tests/mocked-ver", 80 Tags: []string{"k:v"}, 81 TargetAudience: []string{"user:audience@example.com"}, 82 TargetServices: []string{"*"}, 83 TokenId: "1234", 84 TokenKind: messages.Subtoken_BEARER_DELEGATION_TOKEN, 85 }) 86 }) 87 }