gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
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
'use strict';
 
const assert = require('assert');
const isEligibleRequest = require('../lib/isEligibleRequest');
 
describe('isEligibleRequest function tests', () => {
  it('should return true if the request method is POST & headers set', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, true);
  });
  it('should return true if the request method is PUT & headers set', () => {
    const req = {
      method: 'PUT',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, true);
  });
  it('should return true if the request method is PATCH & headers set', () => {
    const req = {
      method: 'PATCH',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, true);
  });
  it('should return false if the request method is POST & content length 0', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-length': '0',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is POST & no content-length', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is POST & no boundary', () => {
    const req = {
      method: 'POST',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; ----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'GET',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'DELETE',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'OPTIONS',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request method is not POST, PUT or PATCH', () => {
    const req = {
      method: 'HEAD',
      headers: {
        'content-length': '768751',
        'content-type': 'multipart/form-data; boundary=----WebKitFormBoundaryz2D47BnVMA7w5N36'
      }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
  it('should return false if the request is empty or not provided', () => {
    const result = isEligibleRequest();
    assert.equal(result, false);
  });
  it('should return false if content-type is not specified.', () => {
    const req = {
      method: 'POST',
      headers: { 'content-length': '768751' }
    };
    const result = isEligibleRequest(req);
    assert.equal(result, false);
  });
});