Passed
Pull Request — master (#3154)
by W
08:13 queued 03:37
created

CustomKeyValuePairTest.set_kvp()   A

Complexity

Conditions 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  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
from integration.mistral import base
17
18
from st2client import models
19
20
21
class CustomKeyValuePairTest(base.TestWorkflowExecution):
22
    secret = None
23
24
    @classmethod
25
    def setUpClass(cls):
26
        super(CustomKeyValuePairTest, cls).setUpClass()
27
        cls.set_kvp('foobar', 'foobar', scope='system', secret=cls.secret)
28
        cls.set_kvp('marco', 'polo', scope='user', secret=cls.secret)
29
30
    @classmethod
31
    def tearDownClass(cls):
32
        super(CustomKeyValuePairTest, cls).tearDownClass()
33
        cls.del_kvp('foobar')
34
        cls.del_kvp('marco')
35
36
    @classmethod
37
    def set_kvp(cls, name, value, scope='system', secret=False):
38
        kvp = models.KeyValuePair(
39
            id=name,
40
            name=name,
41
            value=value,
42
            scope=scope,
43
            secret=secret
44
        )
45
46
        cls.st2client.keys.update(kvp)
47
48
    @classmethod
49
    def del_kvp(cls, name, scope='system'):
50
        kvp = models.KeyValuePair(
51
            id=name,
52
            name=name,
53
            scope=scope
54
        )
55
56
        cls.st2client.keys.delete(kvp)
57
58
59
class UnencryptedKeyValuePairTest(CustomKeyValuePairTest):
60
    secret = False
61
62
    def test_yaql_system_kvp(self):
63
        execution = self._execute_workflow('examples.mistral-yaql-st2kv-system-scope')
64
        execution = self._wait_for_completion(execution)
65
        self._assert_success(execution, num_tasks=1)
66
67
    def test_yaql_user_kvp(self):
68
        execution = self._execute_workflow('examples.mistral-yaql-st2kv-user-scope')
69
        execution = self._wait_for_completion(execution)
70
        self._assert_success(execution, num_tasks=1)
71
72
    def test_jinja_system_kvp(self):
73
        execution = self._execute_workflow('examples.mistral-jinja-st2kv-system-scope')
74
        execution = self._wait_for_completion(execution)
75
        self._assert_success(execution, num_tasks=1)
76
77
    def test_jinja_user_kvp(self):
78
        # Pending completion of jinja rendering of user scoped variable.
79
        # https://github.com/StackStorm/st2/pull/2931
80
        pass
81
82
83
class EncryptedKeyValuePairTest(CustomKeyValuePairTest):
84
    secret = True
85
86
    def test_yaql_system_kvp(self):
87
        execution = self._execute_workflow('examples.mistral-yaql-st2kv-system-scope')
88
        execution = self._wait_for_completion(execution)
89
        self._assert_success(execution, num_tasks=1)
90
91
    def test_yaql_user_kvp(self):
92
        execution = self._execute_workflow('examples.mistral-yaql-st2kv-user-scope')
93
        execution = self._wait_for_completion(execution)
94
        self._assert_success(execution, num_tasks=1)
95
96
    def test_jinja_system_kvp(self):
97
        execution = self._execute_workflow('examples.mistral-jinja-st2kv-system-scope-encrypted')
98
        execution = self._wait_for_completion(execution)
99
        self._assert_success(execution, num_tasks=1)
100
101
    def test_jinja_user_kvp(self):
102
        # Per https://docs.stackstorm.com/datastore.html#storing-secrets,
103
        # decrypting user scoped variables is currently unsupported.
104
        pass
105