-
Notifications
You must be signed in to change notification settings - Fork 47
feat: support network logs obfuscation #380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
33493bb
Create Network Manager
a7medev ce66bd7
Test Network Manager
a7medev 8c34258
Utilize Network Manager inside Network Logger
a7medev cec6a2e
Test obfuscateLog API in network logger
a7medev 50fa9f2
Update Changelog
a7medev 62f138f
Disable native auto-capturing of network logs
a7medev 187d2e5
docs: Add docs to obfuscateLog
abdelhamid-f-nasser 96b7e1c
chore: move obfuscateLog docs to network logger
a7medev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import <Instabug/Instabug.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface IBGNetworkLogger (CP) | ||
|
||
+ (void)disableAutomaticCapturingOfNetworkLogs; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:instabug_flutter/instabug_flutter.dart'; | ||
|
||
typedef ObfuscateLogCallback = FutureOr<NetworkData> Function(NetworkData data); | ||
|
||
/// Mockable [NetworkManager] responsible for processing network logs | ||
/// before they are sent to the native SDKs. | ||
class NetworkManager { | ||
ObfuscateLogCallback? _obfuscateLogCallback; | ||
|
||
// ignore: use_setters_to_change_properties | ||
void setObfuscateLogCallback(ObfuscateLogCallback callback) { | ||
_obfuscateLogCallback = callback; | ||
} | ||
|
||
FutureOr<NetworkData> obfuscateLog(NetworkData data) { | ||
if (_obfuscateLogCallback == null) { | ||
return data; | ||
} | ||
|
||
return _obfuscateLogCallback!(data); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:instabug_flutter/instabug_flutter.dart'; | ||
import 'package:instabug_flutter/src/utils/network_manager.dart'; | ||
|
||
void main() { | ||
TestWidgetsFlutterBinding.ensureInitialized(); | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
final data = NetworkData( | ||
url: "https://httpbin.org/get", | ||
method: "GET", | ||
startTime: DateTime.now(), | ||
); | ||
late NetworkManager manager; | ||
|
||
setUp(() { | ||
manager = NetworkManager(); | ||
}); | ||
|
||
test('[obfuscateLog] should return same data when obfuscate log callback', | ||
() async { | ||
final result = await manager.obfuscateLog(data); | ||
|
||
expect(result, equals(data)); | ||
}); | ||
|
||
test( | ||
'[obfuscateLog] should obfuscate data when [setObfuscateLogCallback] has set a callback', | ||
() async { | ||
final obfuscated = data.copyWith(requestBody: 'obfuscated'); | ||
final completer = Completer<NetworkData>(); | ||
FutureOr<NetworkData> callback(NetworkData data) { | ||
completer.complete(data); | ||
return obfuscated; | ||
} | ||
|
||
manager.setObfuscateLogCallback(callback); | ||
|
||
final result = await manager.obfuscateLog(data); | ||
|
||
expect(completer.isCompleted, isTrue); | ||
|
||
expect(await completer.future, data); | ||
|
||
expect(result, equals(obfuscated)); | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.