|
9 | 9 | faketemplatev1 "github.com/openshift/client-go/template/clientset/versioned/typed/template/v1/fake"
|
10 | 10 | templateapi "github.com/openshift/origin/pkg/template/apis/template"
|
11 | 11 | "github.com/openshift/origin/pkg/templateservicebroker/openservicebroker/api"
|
| 12 | + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" |
12 | 13 |
|
13 | 14 | authorizationv1 "k8s.io/api/authorization/v1"
|
14 | 15 | "k8s.io/apimachinery/pkg/api/errors"
|
@@ -141,6 +142,49 @@ func TestEvaluateJSONPathExpression(t *testing.T) {
|
141 | 142 | }
|
142 | 143 | }
|
143 | 144 |
|
| 145 | +func TestBase64AndString(t *testing.T) { |
| 146 | + t.Skip("this test is demonstrating the generic failure of the export value code for base64. You can't generic identify the base64 fields.") |
| 147 | + data := []byte(`{ |
| 148 | + "apiVersion": "v1", |
| 149 | + "data": { |
| 150 | + "password": "c2VjcmV0Y3JlZHN5bmMK", |
| 151 | + "username": "c2VjcmV0Y3JlZHN5bmMK" |
| 152 | + }, |
| 153 | + "kind": "Secret", |
| 154 | + "metadata": { |
| 155 | + "labels": { |
| 156 | + "credential.sync.jenkins.openshift.io": "true" |
| 157 | + }, |
| 158 | + "name": "secret-to-credential" |
| 159 | + }, |
| 160 | + "type": "Opaque" |
| 161 | +}`) |
| 162 | + |
| 163 | + uncastObj, err := runtime.Decode(unstructured.UnstructuredJSONScheme, data) |
| 164 | + if err != nil { |
| 165 | + t.Fatal(err) |
| 166 | + } |
| 167 | + obj := uncastObj.(*unstructured.Unstructured) |
| 168 | + t.Logf("%T", obj.Object["data"].(map[string]interface{})["password"]) |
| 169 | + |
| 170 | + actualString, err := evaluateJSONPathExpression(obj.Object, "dummy", "{.data.password}", false) |
| 171 | + if err != nil { |
| 172 | + t.Fatal(err) |
| 173 | + } |
| 174 | + if e, a := "secretcredsync", actualString; e != a { |
| 175 | + t.Errorf("expected %q, got %q", e, a) |
| 176 | + } |
| 177 | + |
| 178 | + actualStringAsBase64, err := evaluateJSONPathExpression(obj.Object, "dummy", "{.data.password}", true) |
| 179 | + if err != nil { |
| 180 | + t.Fatal(err) |
| 181 | + } |
| 182 | + if e, a := "c2VjcmV0Y3JlZHN5bmMK", actualStringAsBase64; e != a { |
| 183 | + t.Errorf("expected %q, got %q", e, a) |
| 184 | + } |
| 185 | + |
| 186 | +} |
| 187 | + |
144 | 188 | func TestDuplicateCredentialKeys(t *testing.T) {
|
145 | 189 | credentials := map[string]interface{}{}
|
146 | 190 | err := updateCredentialsForObject(credentials, &kapi.Secret{
|
|
0 commit comments