-
Notifications
You must be signed in to change notification settings - Fork 0
Testsnyk #3
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
base: main
Are you sure you want to change the base?
Testsnyk #3
Changes from all commits
86e68fd
3ed64ae
75cc721
73d4239
771453c
8ab81a9
da89c4e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: Snyk Code Scan | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| snyk: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up Snyk CLI | ||
| uses: snyk/actions/setup@master # Correct action tag | ||
|
|
||
| - name: Authenticate with Snyk | ||
| run: snyk auth ${{ secrets.SNYK_TOKEN }} | ||
|
|
||
| - name: Run Snyk Code Analysis | ||
| run: snyk code test --all-projects | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,37 +7,45 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SwiftUI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import SwiftUI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct ContentView: View { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @StateObject private var viewModel = TaskViewModel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @State private var newTaskTitle = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @State private var newTaskDueDate = Date() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var body: some View { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| VStack { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TextField("Enter task...", text: $newTaskTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .textFieldStyle(RoundedBorderTextFieldStyle()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .padding() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DatePicker("Due Date", selection: $newTaskDueDate, displayedComponents: .date) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .padding() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Button("Add Task") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| viewModel.addTask(title: newTaskTitle) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| newTaskTitle = "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
24
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due date is not used when adding a task. The "Add Task" button action doesn't pass the selected due date to the task creation process, making the date picker non-functional. Button("Add Task") {
- viewModel.addTask(title: newTaskTitle)
+ viewModel.addTask(title: newTaskTitle, dueDate: newTaskDueDate)
newTaskTitle = ""
+ newTaskDueDate = Date()
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| TaskSummaryView( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| totalTasks: viewModel.tasks.count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| completedTasks: viewModel.completedTasks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| overdueTasks: viewModel.overdueTasks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ForEach(viewModel.tasks) { task in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| HStack { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Text(task.title) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Spacer() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Text(task.dueDate?.formatted(date: .abbreviated, time: .omitted) ?? "No Due Date") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .font(.caption) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.gray) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Button(action: { viewModel.toggleComplete(task) }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Image(systemName: task.isCompleted ? "checkmark.circle.fill" : "circle") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
35
to
48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding task deletion functionality. The UI shows tasks but doesn't provide a way to delete them, despite having the List {
ForEach(viewModel.tasks) { task in
HStack {
Text(task.title)
Spacer()
Text(task.dueDate?.formatted(date: .abbreviated, time: .omitted) ?? "No Due Date")
.font(.caption)
.foregroundColor(.gray)
Button(action: { viewModel.toggleComplete(task) }) {
Image(systemName: task.isCompleted ? "checkmark.circle.fill" : "circle")
}
}
}
+ .onDelete { indexSet in
+ indexSet.forEach { index in
+ viewModel.removeTask(viewModel.tasks[index])
+ }
+ }
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Text("Total: \(viewModel.tasks.count) • Completed: \(viewModel.tasks.filter { $0.isCompleted }.count)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .padding(.top) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .padding() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // | ||
| // TaskSummaryView.swift | ||
| // AIReviewSwiftUI | ||
| // | ||
| // Created by kanagasabapathy on 25.04.25. | ||
| // | ||
|
|
||
| import SwiftUI | ||
|
|
||
| struct TaskSummaryView: View { | ||
| let totalTasks: Int | ||
| let completedTasks: Int | ||
| let overdueTasks: Int | ||
|
|
||
| var body: some View { | ||
| VStack { | ||
| Text("Task Summary") | ||
| .font(.headline) | ||
| .padding(.bottom, 8) | ||
|
|
||
| HStack { | ||
| Text("Total Tasks:") | ||
| Spacer() | ||
| Text("\(totalTasks)") | ||
| } | ||
| .padding(.vertical, 4) | ||
|
|
||
| HStack { | ||
| Text("Completed Tasks:") | ||
| Spacer() | ||
| Text("\(completedTasks)") | ||
| } | ||
| .padding(.vertical, 4) | ||
|
|
||
| HStack { | ||
| Text("Overdue Tasks:") | ||
| Spacer() | ||
| Text("\(overdueTasks)") | ||
| } | ||
| .padding(.vertical, 4) | ||
| } | ||
| .padding() | ||
| .background(RoundedRectangle(cornerRadius: 10).fill(Color(.systemGray6))) | ||
| .padding() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,17 +7,38 @@ | |||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| import Foundation | ||||||||||||||||||
| import CryptoKit | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| final class TaskViewModel: ObservableObject { | ||||||||||||||||||
| @Published var tasks: [Task] = [] | ||||||||||||||||||
|
|
||||||||||||||||||
| let urlString = "https://dummyjson.com/products" | ||||||||||||||||||
| let password = "user-password" | ||||||||||||||||||
| let userInput = "example.com" | ||||||||||||||||||
|
|
||||||||||||||||||
| func addTask(title: String) { | ||||||||||||||||||
| guard !title.isEmpty else { return } | ||||||||||||||||||
| let url = URL(string: urlString)! | ||||||||||||||||||
| let hashed = Insecure.MD5.hash(data: password.data(using: .utf8)!) | ||||||||||||||||||
| let urlExample = URL(string: "https://\(userInput)")! | ||||||||||||||||||
|
Comment on lines
+22
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security: Remove unused security-sensitive operations. These lines create security risks without providing any functionality:
- let url = URL(string: urlString)!
- let hashed = Insecure.MD5.hash(data: password.data(using: .utf8)!)
- let urlExample = URL(string: "https://\(userInput)")!If these operations are needed for actual functionality:
📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: Snyk Code Scan[error] 24-24: Use of Hardcoded Credentials: Do not hardcode passwords in code. Found hardcoded password used in password. [error] 24-24: Use of Password Hash With Insufficient Computational Effort: The MD5 hash (used by hash) is insecure. Consider changing it to a secure hash algorithm. |
||||||||||||||||||
| tasks.append(Task(title: title)) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| func toggleComplete(_ task: Task) { | ||||||||||||||||||
| guard let index = tasks.firstIndex(where: { $0.id == task.id }) else { return } | ||||||||||||||||||
| tasks[index].isCompleted.toggle() | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| func removeTask(_ task: Task) { | ||||||||||||||||||
| guard let index = tasks.firstIndex(where: { $0.id == task.id }) else { return } | ||||||||||||||||||
| tasks.remove(at: index) | ||||||||||||||||||
| } | ||||||||||||||||||
| var completedTasks: Int { | ||||||||||||||||||
| tasks.filter { $0.isCompleted }.count | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| var overdueTasks: Int { | ||||||||||||||||||
| let now = Date() | ||||||||||||||||||
| return tasks.filter { !$0.isCompleted && ($0.dueDate ?? now) < now }.count | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+40
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve overdue task calculation logic. The current implementation has a potential logic issue. Using var overdueTasks: Int {
let now = Date()
- return tasks.filter { !$0.isCompleted && ($0.dueDate ?? now) < now }.count
+ return tasks.filter { !$0.isCompleted && $0.dueDate != nil && $0.dueDate! < now }.count
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Pin Snyk setup action to a stable release.
Referencing
snyk/actions/setup@mastercan introduce risk if the default branch changes. We recommend pinning to a tagged version (e.g.,@v1) for reproducibility:📝 Committable suggestion