Coverage Report

Created: 2025-10-26 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openweave-core/src/test-apps/PASEEngineTest.h
Line
Count
Source
1
/*
2
 *
3
 *    Copyright (c) 2013-2017 Nest Labs, Inc.
4
 *    All rights reserved.
5
 *
6
 *    Licensed under the Apache License, Version 2.0 (the "License");
7
 *    you may not use this file except in compliance with the License.
8
 *    You may obtain a copy of the License at
9
 *
10
 *        http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 *    Unless required by applicable law or agreed to in writing, software
13
 *    distributed under the License is distributed on an "AS IS" BASIS,
14
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 *    See the License for the specific language governing permissions and
16
 *    limitations under the License.
17
 */
18
19
#ifndef PASEENGINETEST_H
20
#define PASEENGINETEST_H
21
22
extern const char * INITIATOR_STEP_1;
23
extern const char * RESPONDER_RECONFIGURE;
24
extern const char * RESPONDER_STEP_1;
25
extern const char * RESPONDER_STEP_2;
26
extern const char * INITIATOR_STEP_2;
27
extern const char * RESPONDER_KEY_CONFIRM;
28
29
30
class MessageMutator
31
{
32
public:
33
    virtual void MutateMessage(const char *msgName, PacketBuffer *msgBuf);
34
17.1k
    virtual ~MessageMutator() { }
35
};
36
37
class MessageExternalFuzzer : public MessageMutator
38
{
39
public:
40
    MessageExternalFuzzer(const char *msgType);
41
    virtual void MutateMessage(const char *msgType, PacketBuffer *msgBuf);
42
    MessageExternalFuzzer& FuzzInput(const uint8_t *val, size_t size);
43
    MessageExternalFuzzer& SaveCorpusFile(bool val);
44
45
private:
46
    void SaveCorpus(const uint8_t *inBuf, size_t size, const char *fileName);
47
    const char *mMsgType;
48
    const uint8_t *mFuzzInput;
49
    size_t mFuzzInputSize;
50
    bool mSaveCorpus;
51
};
52
53
class PASEEngineTest
54
{
55
public:
56
    PASEEngineTest(const char *testName);
57
    const char *TestName() const;
58
59
    uint32_t ProposedConfig() const;
60
    PASEEngineTest& ProposedConfig(uint32_t val);
61
62
    uint32_t InitiatorAllowedConfigs() const;
63
    PASEEngineTest& InitiatorAllowedConfigs(uint32_t val);
64
65
    uint32_t ResponderAllowedConfigs() const;
66
    PASEEngineTest& ResponderAllowedConfigs(uint32_t val);
67
68
    const char* InitiatorPassword() const;
69
    PASEEngineTest& InitiatorPassword(const char* val);
70
71
    const char* ResponderPassword() const;
72
    PASEEngineTest& ResponderPassword(const char* val);
73
74
    uint32_t ExpectReconfig() const;
75
    PASEEngineTest& ExpectReconfig(uint32_t expectedConfig);
76
    uint32_t ExpectedConfig() const;
77
78
    bool PerformReconfig() const;
79
    PASEEngineTest& PerformReconfig(bool val);
80
81
    bool ConfirmKey() const;
82
    PASEEngineTest& ConfirmKey(bool val);
83
84
    PASEEngineTest& ExpectError(WEAVE_ERROR err);
85
    PASEEngineTest& ExpectError(const char *opName, WEAVE_ERROR err);
86
87
    bool IsExpectedError(const char *opName, WEAVE_ERROR err) const;
88
    bool IsSuccessExpected() const;
89
90
    PASEEngineTest& Mutator(MessageMutator *mutator);
91
92
    bool LogMessageData() const;
93
    PASEEngineTest& LogMessageData(bool val);
94
95
    void Run();
96
97
private:
98
    void setAllowedResponderConfigs(WeavePASEEngine &responderEng);
99
    enum
100
    {
101
        kMaxExpectedErrors = 32
102
    };
103
104
    struct ExpectedError
105
    {
106
        const char *OpName;
107
        WEAVE_ERROR Error;
108
    };
109
    const char *mTestName;
110
    uint32_t mProposedConfig;
111
    const char *mInitPW;
112
    const char *mRespPW;
113
    uint32_t mInitiatorAllowedConfigs;
114
    uint32_t mResponderAllowedConfigs;
115
    bool mExpectReconfig;
116
    uint32_t mExpectedConfig;
117
    bool mConfirmKey;
118
    bool mForceRepeatedReconfig;
119
    ExpectedError mExpectedErrors[kMaxExpectedErrors];
120
    MessageMutator *mMutator;
121
    bool mLogMessageData;
122
};
123
#endif // PASEENGINETEST_H