github.com/google/osv-scalibr@v0.4.1/veles/secrets/github/checksum/checksum_test.go (about) 1 // Copyright 2025 Google LLC 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 checksum_test 16 17 import ( 18 "testing" 19 20 "github.com/google/osv-scalibr/veles/secrets/github/checksum" 21 ) 22 23 func TestValidateChecksum(t *testing.T) { 24 testcases := []struct { 25 name string 26 token string 27 want bool 28 }{ 29 { 30 name: "example valid", 31 token: `ghr_OWOCPzqKuy3J4w53QpkLfffjBUJSh5yLnFHj7wiyR0NDadVOcykNkoqhoYYXM1yy2sOpAu0lG8fw`, 32 want: true, 33 }, 34 { 35 name: "another example valid", 36 token: `ghu_aGgfQsQ52sImE9zwWxKcjt2nhESfYG1U2FhX`, 37 want: true, 38 }, 39 { 40 name: "invalid token", 41 token: `fjneiwnfewkfew`, 42 want: false, 43 }, 44 { 45 name: "invalid checksum", 46 token: `ghr_OWOCPzqKuy3J4w53QpkLfffjBUJSh5yLnFHj7wiyR0NDadVOcykNkoqhoYYXM1yy2sOpAu0lG1fw`, 47 want: false, 48 }, 49 } 50 51 for _, tc := range testcases { 52 t.Run(tc.name, func(t *testing.T) { 53 t.Parallel() 54 55 got := checksum.Validate([]byte(tc.token)) 56 if got != tc.want { 57 t.Errorf("ValidateChecksum() = %t, want %t", got, tc.want) 58 } 59 }) 60 } 61 }