-
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathHackvertorVariableTest.java
More file actions
135 lines (118 loc) · 5 KB
/
HackvertorVariableTest.java
File metadata and controls
135 lines (118 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package burp;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test to verify Hackvertor variable functionality
*/
public class HackvertorVariableTest extends BaseHackvertorTest {
@Test
void testSetAndGetVariable() {
// Basic set and get variable
String input = "<@set_variable1(false)>foo</@set_variable1>\n\n<@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("foo\n\nfoo", result);
}
@Test
void testGetVariableBeforeSet() {
// Get variable can be used before set variable
String input = "<@get_variable1/>\n\n<@set_variable1(false)>foo</@set_variable1>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("foo\n\nfoo", result);
}
@Test
void testMultipleVariables() {
// Test multiple different variables
String input = "<@set_variable1(false)>foo</@set_variable1>\n" +
"<@set_variable2(false)>bar</@set_variable2>\n" +
"<@get_variable1/> <@get_variable2/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("foo\nbar\nfoo bar", result);
}
@Test
void testVariableOverwrite() {
// Test overwriting a variable
String input = "<@set_variable1(false)>foo</@set_variable1>\n" +
"<@set_variable1(false)>bar</@set_variable1>\n" +
"<@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("foo\nbar\nbar", result);
}
@Test
void testVariableWithTags() {
// Test setting a variable with tag content
String input = "<@set_variable1(false)><@base64>test</@base64></@set_variable1>\n" +
"<@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("dGVzdA==\ndGVzdA==", result);
}
@Test
void testVariableInExpression() {
// Test using variable content in another tag
String input = "<@set_variable1(false)>hello</@set_variable1>\n" +
"<@uppercase><@get_variable1/></@uppercase>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("hello\nHELLO", result);
}
@Test
void testMultipleGetSameVariable() {
// Test getting the same variable multiple times
String input = "<@set_variable1(false)>test</@set_variable1>\n" +
"<@get_variable1/> <@get_variable1/> <@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("test\ntest test test", result);
}
@Test
void testVariableWithComplexContent() {
// Test variable with complex nested content
String input = "<@set_variable1(false)><@hex><@uppercase>abc</@uppercase></@hex></@set_variable1>\n" +
"Result: <@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("414243\nResult: 414243", result);
}
@Test
void testEmptyVariable() {
// Test setting an empty variable
String input = "<@set_variable1(false)></@set_variable1>\n" +
"Value: '<@get_variable1/>'";
String result = hackvertor.convert(input, hackvertor);
assertEquals("\nValue: ''", result);
}
@Test
void testVariableWithBooleanTrue() {
// Test variable with boolean parameter set to true
String input = "<@set_variable1(true)>foo</@set_variable1>\n" +
"<@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
// When boolean is true, it might affect output differently
// Based on the expected behavior, adjust this assertion
assertEquals("foo\nfoo", result);
}
@Test
void testGetUndefinedVariable() {
// Test getting a variable that was never set
String input = "<@get_undefined_variable/>";
String result = hackvertor.convert(input, hackvertor);
// Undefined variables return null
assertEquals("null", result);
}
@Test
void testVariableAcrossMultipleLines() {
// Test variable with multiline content
String input = "<@set_variable1(false)>line1\nline2\nline3</@set_variable1>\n" +
"<@get_variable1/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("line1\nline2\nline3\nline1\nline2\nline3", result);
}
@Test
void testSelfClosingTagWithSpace() {
String input = "<@set_x(false)>123</@set_x><@get_x />";
String result = hackvertor.convert(input, hackvertor);
assertEquals("123123", result);
}
@Test
void testSelfClosingTagWithoutSpace() {
String input = "<@set_x(false)>123</@set_x><@get_x/>";
String result = hackvertor.convert(input, hackvertor);
assertEquals("123123", result);
}
}