1 /* 2 Copyright © 2022 Chris Mellard chris.mellard@icloud.com 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 package credhelper 17 18 import "testing" 19 20 // TestIsACRHelper tests whether URLs are detected as being ACR/MCR registry 21 // hosts, to determine whether the cred helper should fail fast. 22 func TestIsACRHelper(t *testing.T) { 23 for _, c := range []struct { 24 url string 25 want bool 26 }{ 27 {"myregistry.azurecr.io", true}, 28 {"myregistry.azurecr.cn", true}, 29 {"myregistry.azurecr.de", true}, 30 {"myregistry.azurecr.us", true}, 31 {"mcr.microsoft.com", true}, 32 {"myregistry.azurecr.me", false}, // not a known tld 33 {"notacr.xcr.example", false}, 34 {"127.0.0.1:12345", false}, 35 {"localhost:12345", false}, 36 {"notaurl-)(*$@)(*@)(*", false}, 37 } { 38 t.Run(c.url, func(t *testing.T) { 39 got := isACRRegistry(c.url) 40 if got != c.want { 41 t.Fatalf("got %t, want %t", got, c.want) 42 } 43 }) 44 } 45 } 46