yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aws/keypair_test.go (about)

     1  // Copyright 2019 Yunion
     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 aws
    16  
    17  import "testing"
    18  
    19  type testPublicKey struct {
    20  	publickey   string
    21  	fingerprint string
    22  }
    23  
    24  func TestMd5Fingerprint(t *testing.T) {
    25  	rsa := testPublicKey{
    26  		"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCBBuv9nsAGNpKVulxNc7zHXEEyiTqYU8J6sTfmB9lmrRea/RO/pUJg1ZGlHKLSbZ5h+d4mquASf8K3s3SQtz/4sBHroRijanO16i0Rk6t5kwcIRzaf11NiImImKgwNiCwZyiK2egAfsjDVEi8H+kSRA0N0PMxRfwOEZ/hNtVaNV7/MwkXylOuWUikGvPpm3sRmelfQoS3Hf055WM1m6POgddbjucq9bjQDW1O4dfDkWuX+385EOtfCBPtfeiAcOBBd+qEjmdfxroQwxHXLkZH7rdoS9jss3fi9P/K0ZpBKswKsed2sxKo9NNYfTDN19Kv8NBOW8W7MxN1po/2gvbd/",
    27  		"4c:ae:76:94:fb:59:66:8c:a6:07:e2:54:2f:14:19:c5",
    28  	}
    29  
    30  	testKeys := []testPublicKey{rsa}
    31  
    32  	for _, k := range testKeys {
    33  		fingerprint, err := md5Fingerprint(k.publickey)
    34  		if err != nil {
    35  			t.Error(err)
    36  			continue
    37  		}
    38  
    39  		if fingerprint != k.fingerprint {
    40  			t.Errorf("ssh-rsa fingerprint is not as expected.%s != %s", fingerprint, k.fingerprint)
    41  			continue
    42  		}
    43  	}
    44  }