Skip to content
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

#823 Added obfuscate option to dump shards #837

Merged
merged 14 commits into from
Jun 19, 2020

Conversation

piotradamczyk5
Copy link
Contributor

@piotradamczyk5 piotradamczyk5 commented Jun 5, 2020

Fixes #823

Test Plan

How do we know the code works?

run
flank [android|ios] run --dump-shards --obfuscate
and compare output file with running
flank [android|ios] run --dump-shards
Check ObfuscationTest for checking obfuscation results

Checklist

  • Documented
  • Unit tested
  • release_notes.md updated

@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2020

Codecov Report

Merging #837 into master will increase coverage by 0.32%.
The diff coverage is 96.55%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #837      +/-   ##
============================================
+ Coverage     81.23%   81.56%   +0.32%     
  Complexity      637      637              
============================================
  Files           167      169       +2     
  Lines          3240     3292      +52     
  Branches        463      467       +4     
============================================
+ Hits           2632     2685      +53     
+ Misses          343      341       -2     
- Partials        265      266       +1     

@piotradamczyk5
Copy link
Contributor Author

I pushed all documentation changes which were generated

class ObfuscationGsonTest {

@Test
fun `Should return gson with correct type adapters registered`() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere we starting test name from lower letter. Maybe we should keep always same naming convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@adamfilipow92
Copy link
Contributor

If you add new command you should update

  • README.md
  • flank.yml
  • flank.ios.yml

@piotradamczyk5
Copy link
Contributor Author

piotradamczyk5 commented Jun 5, 2020

If you add new command you should update

  • README.md
  • flank.yml
  • flank.ios.yml

this is CLI option not flank settings. --dump-shards option is also missed there

@adamfilipow92
Copy link
Contributor

If you add new command you should update

  • README.md
  • flank.yml
  • flank.ios.yml

this is CLI option not flank settings. --dump-shards option is also missed there

Right, sorry!

adamfilipow92
adamfilipow92 previously approved these changes Jun 5, 2020
Copy link
Contributor

@adamfilipow92 adamfilipow92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -47,7 +47,7 @@ class AndroidRunCommand : CommonRunCommand(), Runnable {

runBlocking {
if (dumpShards)
dumpShards(config) else
dumpShards(args = config, obfuscatedOutput = obfuscate) else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why obfuscate is passed via function argument? It shouldn't be in CommonArgs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is CLI option which are not in Common args, so I would like to make them same as others

}
}

private object ObfusctedIosJsonSerializer : JsonSerializer<List<List<String>>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, should be ObfuscatedIosJsonSerializer

@VisibleForTesting
internal object ListOfStringListTypeToken : TypeToken<ShardChunks>()

private object ObfusctedAndroidJsonSerializer : JsonSerializer<List<String>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, should be ObfuscatedAndroidJsonSerializer

private const val UPPER_CASE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
private const val START_CONTEXT_KEY = ""

interface Obfuscation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant abstraction if you remove this interface everything will work as well, so that means it is not needed. Keep it simple


class AndroidObfuscation : Obfuscation {
private val contextMapAndroid = mutableMapOf<String, MutableMap<String, String>>()
private val androidTestMethodSeparator = '#'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not configurable so it could be const

private object ObfusctedAndroidJsonSerializer : JsonSerializer<List<String>> {
private val obfuscation by lazy { AndroidObfuscation() }

override fun serialize(src: List<String>?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that any any of this args could be null? IMO not.

}

private fun obfuscateAndroidPackageAndClass(packageNameWithClass: String): String {
return packageNameWithClass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be expression

}

private fun obfuscateMethodName(methodName: String, context: MutableMap<String, String>): String {
return context.getOrPut(methodName) { nextSymbol(methodName, context) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be expression

fun obfuscate(input: String): String
}

class AndroidObfuscation : Obfuscation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You already know my opinion about object oriented programming. Do we really need class for that I guess it's unnecessary complication to bound functions with state. I could be simple function like that:

typealias ObfuscationContext = Map<String, MutableMap<String, String>>

fun ObfuscationContext.obfuscateAndroidTestMethod(input: String): String {
    ...
}

The same about ios.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was to keep it state, however it could be done much better by keeping context and make extension function. Thank you, for this idea

private fun obfuscateAndroidPackageAndClass(packageNameWithClass: String): String {
return packageNameWithClass
.split(androidPackageSeparator)
.fold(START_CONTEXT_KEY) { previous, next ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, START_CONTEXT_KEY is redundant. fold("") is better than fold(START_CONTEXT_KEY) because START_CONTEXT_KEY forces to remember next name, and scroll to check what value it holds.

@piotradamczyk5
Copy link
Contributor Author

this task must be updated after merging #853

Piotr Adamczyk added 4 commits June 17, 2020 15:05
# Conflicts:
#	release_notes.md
#	test_runner/docs/ascii/flank.jar_-android-run.adoc
#	test_runner/docs/ascii/flank.jar_-firebase-test-android-run.adoc
#	test_runner/docs/ascii/flank.jar_-firebase-test-ios-run.adoc
#	test_runner/docs/ascii/flank.jar_-ios-run.adoc
…-obfuscation-option

# Conflicts:
#	release_notes.md
Copy link
Contributor

@adamfilipow92 adamfilipow92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@piotradamczyk5 piotradamczyk5 merged commit 23d66ed into master Jun 19, 2020
@piotradamczyk5 piotradamczyk5 deleted the #823-add-dump-shard-obfuscation-option branch June 19, 2020 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flank run --dump-shards --obfuscate
4 participants