checkFlows checks a single completed flow against another required one. If one contains at least all of the stages that the other does, checkFlows returns true.
( completedStages []authtypes.LoginType, requiredStages []authtypes.LoginType, )
| 955 | // one contains at least all of the stages that the other does, checkFlows |
| 956 | // returns true. |
| 957 | func checkFlows( |
| 958 | completedStages []authtypes.LoginType, |
| 959 | requiredStages []authtypes.LoginType, |
| 960 | ) bool { |
| 961 | // Create temporary slices so they originals will not be modified on sorting |
| 962 | completed := make([]authtypes.LoginType, len(completedStages)) |
| 963 | required := make([]authtypes.LoginType, len(requiredStages)) |
| 964 | copy(completed, completedStages) |
| 965 | copy(required, requiredStages) |
| 966 | |
| 967 | // Sort the slices for simple comparison |
| 968 | sort.Slice(completed, func(i, j int) bool { return completed[i] < completed[j] }) |
| 969 | sort.Slice(required, func(i, j int) bool { return required[i] < required[j] }) |
| 970 | |
| 971 | // Iterate through each slice, going to the next required slice only once |
| 972 | // we've found a match. |
| 973 | i, j := 0, 0 |
| 974 | for j < len(required) { |
| 975 | // Exit if we've reached the end of our input without being able to |
| 976 | // match all of the required stages. |
| 977 | if i >= len(completed) { |
| 978 | return false |
| 979 | } |
| 980 | |
| 981 | // If we've found a stage we want, move on to the next required stage. |
| 982 | if completed[i] == required[j] { |
| 983 | j++ |
| 984 | } |
| 985 | i++ |
| 986 | } |
| 987 | return true |
| 988 | } |
| 989 | |
| 990 | // checkFlowCompleted checks if a registration flow complies with any allowed flow |
| 991 | // dictated by the server. Order of stages does not matter. A user may complete |
no outgoing calls
no test coverage detected