go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/tokenserver/appengine/impl/serviceaccounts/bigquery_log_test.go (about) 1 // Copyright 2020 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 serviceaccounts 16 17 import ( 18 "net" 19 "testing" 20 "time" 21 22 "google.golang.org/protobuf/types/known/timestamppb" 23 24 bqpb "go.chromium.org/luci/tokenserver/api/bq" 25 "go.chromium.org/luci/tokenserver/api/minter/v1" 26 27 . "github.com/smartystreets/goconvey/convey" 28 . "go.chromium.org/luci/common/testing/assertions" 29 ) 30 31 func TestMintedTokenInfo(t *testing.T) { 32 t.Parallel() 33 34 Convey("Conversion to row", t, func() { 35 info := MintedTokenInfo{ 36 Request: &minter.MintServiceAccountTokenRequest{ 37 TokenKind: minter.ServiceAccountTokenKind_SERVICE_ACCOUNT_TOKEN_ACCESS_TOKEN, 38 ServiceAccount: "acc@example.com", 39 Realm: "proj:realm", 40 OauthScope: []string{"ignored"}, 41 IdTokenAudience: "aud", 42 AuditTags: []string{"k:v"}, 43 }, 44 Response: &minter.MintServiceAccountTokenResponse{ 45 Token: "some-token", 46 Expiry: ×tamppb.Timestamp{Seconds: 123456}, 47 ServiceVersion: "unit-tests/mocked-ver", 48 }, 49 RequestedAt: time.Unix(1234, 0), 50 OAuthScopes: []string{"a", "b"}, 51 RequestIdentity: "user:req@example.com", 52 PeerIdentity: "user:peer@example.com", 53 ConfigRev: "config-rev", 54 PeerIP: net.ParseIP("127.1.1.1"), 55 RequestID: "request-id", 56 AuthDBRev: 111, 57 } 58 59 So(info.toBigQueryMessage(), ShouldResembleProto, &bqpb.ServiceAccountToken{ 60 Fingerprint: "308eda9daf26b7446b284449a5895ab9", 61 Kind: minter.ServiceAccountTokenKind_SERVICE_ACCOUNT_TOKEN_ACCESS_TOKEN, 62 ServiceAccount: "acc@example.com", 63 Realm: "proj:realm", 64 OauthScopes: []string{"a", "b"}, 65 IdTokenAudience: "aud", 66 RequestIdentity: "user:req@example.com", 67 PeerIdentity: "user:peer@example.com", 68 RequestedAt: ×tamppb.Timestamp{Seconds: 1234}, 69 Expiration: ×tamppb.Timestamp{Seconds: 123456}, 70 AuditTags: []string{"k:v"}, 71 ConfigRev: "config-rev", 72 PeerIp: "127.1.1.1", 73 ServiceVersion: "unit-tests/mocked-ver", 74 GaeRequestId: "request-id", 75 AuthDbRev: 111, 76 }) 77 }) 78 }