fiftyone.pipeline.core 4.4.85 → 4.4.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/evidence.js CHANGED
@@ -148,15 +148,22 @@ class Evidence {
148
148
 
149
149
  evidence.add('server.host-ip', request.connection.localAddress.toString());
150
150
 
151
- // Get querystring data
151
+ // Parsing URL using new URL constructor
152
+
153
+ const protocol = request.protocol || 'http';
154
+ const hostname = request.hostname || 'localhost'; // Use a default hostname if not available
155
+ const port = request.socket?.localPort || ''; // Port may not be available in some cases
152
156
 
153
- const params = new url.URL(request.url, true);
157
+ // If request.url already contains the protocol, hostname, and port, use it as is
158
+ const fullURL = request.url.includes('://') ? request.url : `${protocol}://${hostname}${port ? `:${port}` : ''}${request.url}`;
159
+
160
+ // Get querystring data
154
161
 
155
- const query = params.query;
162
+ const URL = new url.URL(fullURL);
163
+ const query = URL.searchParams;
156
164
 
157
- Object.keys(query).forEach(function (key) {
158
- const value = query[key];
159
- evidence.add('query.' + key, value);
165
+ query.forEach(function (value, param) {
166
+ evidence.add('query.' + param, value);
160
167
  });
161
168
 
162
169
  return this;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fiftyone.pipeline.core",
3
- "version": "4.4.85",
3
+ "version": "4.4.87",
4
4
  "description": "Core library for the 51Degrees Pipeline API",
5
5
  "keywords": [
6
6
  "51degrees",
@@ -66,3 +66,65 @@ test('evidenceKeyFilter', () => {
66
66
  )
67
67
  .toBe('header.user_agent');
68
68
  });
69
+
70
+ /**
71
+ * Check that evidence addFromRequest
72
+ * can correctly handle Incoming Request object */
73
+
74
+ test('evidence addFromRequest partial url', () => {
75
+ const { EventEmitter } = require('events');
76
+
77
+ // Mock request object
78
+ const mockRequest = new EventEmitter();
79
+ mockRequest.method = 'POST'; // Example HTTP method
80
+ mockRequest.url = '/?some-value=some'; // Example request URL
81
+ mockRequest.httpVersion = '1.1'; // Example HTTP version
82
+ mockRequest.hostname = 'test.url';
83
+ mockRequest.headers = {
84
+ 'Content-Type': 'application/json',
85
+ 'Content-Length': 18
86
+ }; // Example request headers
87
+
88
+ // Simulating request body data
89
+ const mockBodyData = JSON.stringify({ evidence: 'sample' });
90
+ mockRequest.emit('data', mockBodyData);
91
+ mockRequest.emit('end');
92
+
93
+ // Simulating connection object
94
+ mockRequest.connection = {
95
+ remoteAddress: '127.0.0.1',
96
+ localAddress: '127.0.0.1'
97
+ };
98
+
99
+ expect(() => syncFlowData.evidence.addFromRequest(mockRequest)).not.toThrow();
100
+ expect(syncFlowData.evidence.get('query.some-value')).toBe('some');
101
+ });
102
+
103
+ test('evidence addFromRequest full url', () => {
104
+ const { EventEmitter } = require('events');
105
+
106
+ // Mock request object
107
+ const mockRequest = new EventEmitter();
108
+ mockRequest.method = 'POST'; // Example HTTP method
109
+ mockRequest.url = 'http://test.com/path?some-value=some'; // Example request URL
110
+ mockRequest.httpVersion = '1.1'; // Example HTTP version
111
+ mockRequest.hostname = 'test.url';
112
+ mockRequest.headers = {
113
+ 'Content-Type': 'application/json',
114
+ 'Content-Length': 18
115
+ }; // Example request headers
116
+
117
+ // Simulating request body data
118
+ const mockBodyData = JSON.stringify({ evidence: 'sample' });
119
+ mockRequest.emit('data', mockBodyData);
120
+ mockRequest.emit('end');
121
+
122
+ // Simulating connection object
123
+ mockRequest.connection = {
124
+ remoteAddress: '127.0.0.1',
125
+ localAddress: '127.0.0.1'
126
+ };
127
+
128
+ expect(() => syncFlowData.evidence.addFromRequest(mockRequest)).not.toThrow();
129
+ expect(syncFlowData.evidence.get('query.some-value')).toBe('some');
130
+ });